Skip to content

Commit

Permalink
Merge 2247fa4 into 1fb649d
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaeckel committed Aug 24, 2014
2 parents 1fb649d + 2247fa4 commit 4dcc702
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 142 deletions.
6 changes: 3 additions & 3 deletions src/headers/tomcrypt_pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ int dsa_shared_secret(void *private_key, void *base,
#ifdef LTC_DER
/* DER handling */

enum {
typedef enum ltc_asn1_type_ {
LTC_ASN1_EOL,
LTC_ASN1_BOOLEAN,
LTC_ASN1_INTEGER,
Expand All @@ -455,12 +455,12 @@ enum {
LTC_ASN1_RAW_BIT_STRING,
LTC_ASN1_TELETEX_STRING,
LTC_ASN1_CONSTRUCTED,
};
} ltc_asn1_type;

/** A LTC ASN.1 list type */
typedef struct ltc_asn1_list_ {
/** The LTC ASN.1 enumerated type identifier */
int type;
ltc_asn1_type type;
/** The data to encode or place for decoding */
void *data;
/** The size of the input or resulting output */
Expand Down
39 changes: 36 additions & 3 deletions src/pk/asn1/der/choice/der_decode_choice.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ int der_decode_choice(const unsigned char *in, unsigned long *inlen,
data = list[x].data;

switch (list[x].type) {
case LTC_ASN1_BOOLEAN:
if (der_decode_boolean(in, *inlen, data) == CRYPT_OK) {
if (der_length_boolean(&z) == CRYPT_OK) {
list[x].used = 1;
*inlen = z;
return CRYPT_OK;
}
}
break;

case LTC_ASN1_INTEGER:
if (der_decode_integer(in, *inlen, data) == CRYPT_OK) {
if (der_length_integer(data, &z) == CRYPT_OK) {
Expand Down Expand Up @@ -82,6 +92,17 @@ int der_decode_choice(const unsigned char *in, unsigned long *inlen,
}
break;

case LTC_ASN1_RAW_BIT_STRING:
if (der_decode_raw_bit_string(in, *inlen, data, &size) == CRYPT_OK) {
if (der_length_bit_string(size, &z) == CRYPT_OK) {
list[x].used = 1;
list[x].size = size;
*inlen = z;
return CRYPT_OK;
}
}
break;

case LTC_ASN1_OCTET_STRING:
if (der_decode_octet_string(in, *inlen, data, &size) == CRYPT_OK) {
if (der_length_octet_string(size, &z) == CRYPT_OK) {
Expand All @@ -100,7 +121,7 @@ int der_decode_choice(const unsigned char *in, unsigned long *inlen,
return CRYPT_OK;
}
break;

case LTC_ASN1_OBJECT_IDENTIFIER:
if (der_decode_object_identifier(in, *inlen, data, &size) == CRYPT_OK) {
if (der_length_object_identifier(data, size, &z) == CRYPT_OK) {
Expand All @@ -112,6 +133,17 @@ int der_decode_choice(const unsigned char *in, unsigned long *inlen,
}
break;

case LTC_ASN1_TELETEX_STRING:
if (der_decode_teletex_string(in, *inlen, data, &size) == CRYPT_OK) {
if (der_length_teletex_string(data, size, &z) == CRYPT_OK) {
list[x].used = 1;
list[x].size = size;
*inlen = z;
return CRYPT_OK;
}
}
break;

case LTC_ASN1_IA5_STRING:
if (der_decode_ia5_string(in, *inlen, data, &size) == CRYPT_OK) {
if (der_length_ia5_string(data, size, &z) == CRYPT_OK) {
Expand All @@ -123,7 +155,6 @@ int der_decode_choice(const unsigned char *in, unsigned long *inlen,
}
break;


case LTC_ASN1_PRINTABLE_STRING:
if (der_decode_printable_string(in, *inlen, data, &size) == CRYPT_OK) {
if (der_length_printable_string(data, size, &z) == CRYPT_OK) {
Expand Down Expand Up @@ -167,7 +198,9 @@ int der_decode_choice(const unsigned char *in, unsigned long *inlen,
}
break;

default:
case LTC_ASN1_CHOICE:
case LTC_ASN1_CONSTRUCTED:
case LTC_ASN1_EOL:
return CRYPT_INVALID_ARG;
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/pk/asn1/der/sequence/der_decode_sequence_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
ltc_asn1_list *list, unsigned long outlen, int ordered)
{
int err, type, i;
int err, i;
ltc_asn1_type type;
unsigned long size, x, y, z, blksize;
void *data;

Expand Down Expand Up @@ -187,6 +188,18 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
}
break;

case LTC_ASN1_TELETEX_STRING:
z = inlen;
if ((err = der_decode_teletex_string(in + x, z, data, &size)) != CRYPT_OK) {
if (!ordered) { continue; }
goto LBL_ERR;
}
list[i].size = size;
if ((err = der_length_teletex_string(data, size, &z)) != CRYPT_OK) {
goto LBL_ERR;
}
break;

case LTC_ASN1_IA5_STRING:
z = inlen;
if ((err = der_decode_ia5_string(in + x, z, data, &size)) != CRYPT_OK) {
Expand Down Expand Up @@ -270,7 +283,8 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
}
break;

default:
case LTC_ASN1_CONSTRUCTED:
case LTC_ASN1_EOL:
err = CRYPT_INVALID_ARG;
goto LBL_ERR;
}
Expand Down

0 comments on commit 4dcc702

Please sign in to comment.