trim trailing spaces
This commit is contained in:
parent
3eae4b42fb
commit
a667a93d52
@ -37,7 +37,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
|
|
||||||
LTC_ARGCHK(in != NULL);
|
LTC_ARGCHK(in != NULL);
|
||||||
LTC_ARGCHK(list != NULL);
|
LTC_ARGCHK(list != NULL);
|
||||||
|
|
||||||
/* get blk size */
|
/* get blk size */
|
||||||
if (inlen < 2) {
|
if (inlen < 2) {
|
||||||
return CRYPT_INVALID_PACKET;
|
return CRYPT_INVALID_PACKET;
|
||||||
@ -78,7 +78,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
/* mark all as unused */
|
/* mark all as unused */
|
||||||
for (i = 0; i < (int)outlen; i++) {
|
for (i = 0; i < (int)outlen; i++) {
|
||||||
list[i].used = 0;
|
list[i].used = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ok read data */
|
/* ok read data */
|
||||||
inlen = blksize;
|
inlen = blksize;
|
||||||
@ -89,7 +89,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
data = list[i].data;
|
data = list[i].data;
|
||||||
if (!ordered && list[i].used == 1) { continue; }
|
if (!ordered && list[i].used == 1) { continue; }
|
||||||
|
|
||||||
if (type == LTC_ASN1_EOL) {
|
if (type == LTC_ASN1_EOL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LTC_ASN1_INTEGER:
|
case LTC_ASN1_INTEGER:
|
||||||
z = inlen;
|
z = inlen;
|
||||||
if ((err = der_decode_integer(in + x, z, data)) != CRYPT_OK) {
|
if ((err = der_decode_integer(in + x, z, data)) != CRYPT_OK) {
|
||||||
@ -124,7 +124,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
if ((err = der_length_short_integer(((unsigned long*)data)[0], &z)) != CRYPT_OK) {
|
if ((err = der_length_short_integer(((unsigned long*)data)[0], &z)) != CRYPT_OK) {
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LTC_ASN1_BIT_STRING:
|
case LTC_ASN1_BIT_STRING:
|
||||||
@ -171,7 +171,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
}
|
}
|
||||||
z = 2;
|
z = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LTC_ASN1_OBJECT_IDENTIFIER:
|
case LTC_ASN1_OBJECT_IDENTIFIER:
|
||||||
z = inlen;
|
z = inlen;
|
||||||
if ((err = der_decode_object_identifier(in + x, z, data, &size)) != CRYPT_OK) {
|
if ((err = der_decode_object_identifier(in + x, z, data, &size)) != CRYPT_OK) {
|
||||||
@ -239,7 +239,7 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LTC_ASN1_SETOF:
|
case LTC_ASN1_SETOF:
|
||||||
case LTC_ASN1_SEQUENCE:
|
case LTC_ASN1_SEQUENCE:
|
||||||
/* detect if we have the right type */
|
/* detect if we have the right type */
|
||||||
@ -274,24 +274,24 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
|||||||
x += z;
|
x += z;
|
||||||
inlen -= z;
|
inlen -= z;
|
||||||
list[i].used = 1;
|
list[i].used = 1;
|
||||||
if (!ordered) {
|
if (!ordered) {
|
||||||
/* restart the decoder */
|
/* restart the decoder */
|
||||||
i = -1;
|
i = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < (int)outlen; i++) {
|
for (i = 0; i < (int)outlen; i++) {
|
||||||
if (list[i].used == 0) {
|
if (list[i].used == 0) {
|
||||||
err = CRYPT_INVALID_PACKET;
|
err = CRYPT_INVALID_PACKET;
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = CRYPT_OK;
|
err = CRYPT_OK;
|
||||||
|
|
||||||
LBL_ERR:
|
LBL_ERR:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
@file dh_sys.c
|
@file dh_sys.c
|
||||||
DH Crypto, Tom St Denis
|
DH Crypto, Tom St Denis
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypt a short symmetric key with a public DH key
|
Encrypt a short symmetric key with a public DH key
|
||||||
@param in The symmetric key to encrypt
|
@param in The symmetric key to encrypt
|
||||||
@ -154,7 +154,7 @@ LBL_ERR:
|
|||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||||
unsigned char *out, unsigned long *outlen,
|
unsigned char *out, unsigned long *outlen,
|
||||||
dh_key *key)
|
dh_key *key)
|
||||||
{
|
{
|
||||||
unsigned char *shared_secret, *skey;
|
unsigned char *shared_secret, *skey;
|
||||||
@ -211,7 +211,7 @@ int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
|||||||
|
|
||||||
/* get public key */
|
/* get public key */
|
||||||
LOAD32L(x, in+y);
|
LOAD32L(x, in+y);
|
||||||
|
|
||||||
/* now check if the imported key will fit */
|
/* now check if the imported key will fit */
|
||||||
if (inlen < x) {
|
if (inlen < x) {
|
||||||
err = CRYPT_INVALID_PACKET;
|
err = CRYPT_INVALID_PACKET;
|
||||||
@ -219,7 +219,7 @@ int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
|||||||
} else {
|
} else {
|
||||||
inlen -= x;
|
inlen -= x;
|
||||||
}
|
}
|
||||||
|
|
||||||
y += 4;
|
y += 4;
|
||||||
if ((err = dh_import(in+y, x, &pubkey)) != CRYPT_OK) {
|
if ((err = dh_import(in+y, x, &pubkey)) != CRYPT_OK) {
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
@ -241,7 +241,7 @@ int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
|||||||
|
|
||||||
/* load in the encrypted key */
|
/* load in the encrypted key */
|
||||||
LOAD32L(keysize, in+y);
|
LOAD32L(keysize, in+y);
|
||||||
|
|
||||||
/* will the out fit as part of the input */
|
/* will the out fit as part of the input */
|
||||||
if (inlen < keysize) {
|
if (inlen < keysize) {
|
||||||
err = CRYPT_INVALID_PACKET;
|
err = CRYPT_INVALID_PACKET;
|
||||||
@ -249,7 +249,7 @@ int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
|||||||
} else {
|
} else {
|
||||||
inlen -= keysize;
|
inlen -= keysize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keysize > *outlen) {
|
if (keysize > *outlen) {
|
||||||
err = CRYPT_BUFFER_OVERFLOW;
|
err = CRYPT_BUFFER_OVERFLOW;
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
@ -275,27 +275,27 @@ LBL_ERR:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* perform an ElGamal Signature of a hash
|
/* perform an ElGamal Signature of a hash
|
||||||
*
|
*
|
||||||
* The math works as follows. x is the private key, M is the message to sign
|
* The math works as follows. x is the private key, M is the message to sign
|
||||||
|
|
||||||
1. pick a random k
|
1. pick a random k
|
||||||
2. compute a = g^k mod p
|
2. compute a = g^k mod p
|
||||||
3. compute b = (M - xa)/k mod p
|
3. compute b = (M - xa)/k mod p
|
||||||
4. Send (a,b)
|
4. Send (a,b)
|
||||||
|
|
||||||
Now to verify with y=g^x mod p, a and b
|
Now to verify with y=g^x mod p, a and b
|
||||||
|
|
||||||
1. compute y^a * a^b = g^(xa) * g^(k*(M-xa)/k)
|
1. compute y^a * a^b = g^(xa) * g^(k*(M-xa)/k)
|
||||||
= g^(xa + (M - xa))
|
= g^(xa + (M - xa))
|
||||||
= g^M [all mod p]
|
= g^M [all mod p]
|
||||||
|
|
||||||
2. Compare against g^M mod p [based on input hash].
|
2. Compare against g^M mod p [based on input hash].
|
||||||
3. If result of #2 == result of #1 then signature valid
|
3. If result of #2 == result of #1 then signature valid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sign a message digest using a DH private key
|
Sign a message digest using a DH private key
|
||||||
@param in The data to sign
|
@param in The data to sign
|
||||||
@param inlen The length of the input (octets)
|
@param inlen The length of the input (octets)
|
||||||
@param out [out] The destination of the signature
|
@param out [out] The destination of the signature
|
||||||
@ -338,16 +338,16 @@ int dh_sign_hash(const unsigned char *in, unsigned long inlen,
|
|||||||
|
|
||||||
/* make up a random value k,
|
/* make up a random value k,
|
||||||
* since the order of the group is prime
|
* since the order of the group is prime
|
||||||
* we need not check if gcd(k, r) is 1
|
* we need not check if gcd(k, r) is 1
|
||||||
*/
|
*/
|
||||||
if (prng_descriptor[wprng].read(buf, sets[key->idx].size, prng) !=
|
if (prng_descriptor[wprng].read(buf, sets[key->idx].size, prng) !=
|
||||||
(unsigned long)(sets[key->idx].size)) {
|
(unsigned long)(sets[key->idx].size)) {
|
||||||
err = CRYPT_ERROR_READPRNG;
|
err = CRYPT_ERROR_READPRNG;
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init bignums */
|
/* init bignums */
|
||||||
if ((err = mp_init_multi(&a, &b, &k, &m, &p, &g, &p1, &tmp, NULL)) != CRYPT_OK) {
|
if ((err = mp_init_multi(&a, &b, &k, &m, &p, &g, &p1, &tmp, NULL)) != CRYPT_OK) {
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,13 +369,13 @@ int dh_sign_hash(const unsigned char *in, unsigned long inlen,
|
|||||||
if ((err = mp_mulmod(a, key->x, p1, tmp)) != CRYPT_OK) { goto error; } /* tmp = xa */
|
if ((err = mp_mulmod(a, key->x, p1, tmp)) != CRYPT_OK) { goto error; } /* tmp = xa */
|
||||||
if ((err = mp_submod(m, tmp, p1, tmp)) != CRYPT_OK) { goto error; } /* tmp = M - xa */
|
if ((err = mp_submod(m, tmp, p1, tmp)) != CRYPT_OK) { goto error; } /* tmp = M - xa */
|
||||||
if ((err = mp_mulmod(k, tmp, p1, b)) != CRYPT_OK) { goto error; } /* b = (M - xa)/k */
|
if ((err = mp_mulmod(k, tmp, p1, b)) != CRYPT_OK) { goto error; } /* b = (M - xa)/k */
|
||||||
|
|
||||||
/* check for overflow */
|
/* check for overflow */
|
||||||
if ((unsigned long)(PACKET_SIZE + 4 + 4 + mp_unsigned_bin_size(a) + mp_unsigned_bin_size(b)) > *outlen) {
|
if ((unsigned long)(PACKET_SIZE + 4 + 4 + mp_unsigned_bin_size(a) + mp_unsigned_bin_size(b)) > *outlen) {
|
||||||
err = CRYPT_BUFFER_OVERFLOW;
|
err = CRYPT_BUFFER_OVERFLOW;
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store header */
|
/* store header */
|
||||||
y = PACKET_SIZE;
|
y = PACKET_SIZE;
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ LBL_ERR:
|
|||||||
@return CRYPT_OK if succsessful (even if signature is invalid)
|
@return CRYPT_OK if succsessful (even if signature is invalid)
|
||||||
*/
|
*/
|
||||||
int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
|
int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||||
const unsigned char *hash, unsigned long hashlen,
|
const unsigned char *hash, unsigned long hashlen,
|
||||||
int *stat, dh_key *key)
|
int *stat, dh_key *key)
|
||||||
{
|
{
|
||||||
void *a, *b, *p, *g, *m, *tmp;
|
void *a, *b, *p, *g, *m, *tmp;
|
||||||
@ -441,18 +441,18 @@ int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
|
|||||||
/* check initial input length */
|
/* check initial input length */
|
||||||
if (siglen < PACKET_SIZE+4+4) {
|
if (siglen < PACKET_SIZE+4+4) {
|
||||||
return CRYPT_INVALID_PACKET;
|
return CRYPT_INVALID_PACKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* header ok? */
|
/* header ok? */
|
||||||
if ((err = packet_valid_header((unsigned char *)sig, PACKET_SECT_DH, PACKET_SUB_SIGNED)) != CRYPT_OK) {
|
if ((err = packet_valid_header((unsigned char *)sig, PACKET_SECT_DH, PACKET_SUB_SIGNED)) != CRYPT_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get hash out of packet */
|
/* get hash out of packet */
|
||||||
y = PACKET_SIZE;
|
y = PACKET_SIZE;
|
||||||
|
|
||||||
/* init all bignums */
|
/* init all bignums */
|
||||||
if ((err = mp_init_multi(&a, &p, &b, &g, &m, &tmp, NULL)) != CRYPT_OK) {
|
if ((err = mp_init_multi(&a, &p, &b, &g, &m, &tmp, NULL)) != CRYPT_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user