diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-07-14 11:58:25 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-07-14 11:58:25 +0200 |
commit | 7e36c5726d7ab6b41ff186fae315f039cd4a97be (patch) | |
tree | 275cab9c407747e936bfd78895f6de4e8d4f1c6e /libtomcrypt | |
parent | 161f08b8a15a9b0d2c5aede4a4ffba5bf092b893 (diff) | |
download | kernel-crypto-7e36c5726d7ab6b41ff186fae315f039cd4a97be.tar.gz kernel-crypto-7e36c5726d7ab6b41ff186fae315f039cd4a97be.tar.xz kernel-crypto-7e36c5726d7ab6b41ff186fae315f039cd4a97be.zip |
DSA private keys are exported to a format that is compatible with openssl and gnutls.
Diffstat (limited to 'libtomcrypt')
-rw-r--r-- | libtomcrypt/pk/dsa/dsa_export.c | 19 | ||||
-rw-r--r-- | libtomcrypt/pk/dsa/dsa_import.c | 24 |
2 files changed, 24 insertions, 19 deletions
diff --git a/libtomcrypt/pk/dsa/dsa_export.c b/libtomcrypt/pk/dsa/dsa_export.c index 30145a3c99e..11b66381bb8 100644 --- a/libtomcrypt/pk/dsa/dsa_export.c +++ b/libtomcrypt/pk/dsa/dsa_export.c @@ -28,6 +28,7 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key) { unsigned char flags[1]; + unsigned long zero=0; LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); @@ -44,15 +45,19 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key flags[0] = (type != PK_PUBLIC) ? 1 : 0; + /* This encoding is different from the one in original + * libtomcrypt. It uses a compatible encoding with gnutls + * and openssl + */ if (type == PK_PRIVATE) { return der_encode_sequence_multi(out, outlen, - LTC_ASN1_BIT_STRING, 1UL, flags, - LTC_ASN1_INTEGER, 1UL, &key->g, - LTC_ASN1_INTEGER, 1UL, &key->p, - LTC_ASN1_INTEGER, 1UL, &key->q, - LTC_ASN1_INTEGER, 1UL, &key->y, - LTC_ASN1_INTEGER, 1UL, &key->x, - LTC_ASN1_EOL, 0UL, NULL); + LTC_ASN1_SHORT_INTEGER, 1UL, &zero, + LTC_ASN1_INTEGER, 1UL, &key->p, + LTC_ASN1_INTEGER, 1UL, &key->q, + LTC_ASN1_INTEGER, 1UL, &key->g, + LTC_ASN1_INTEGER, 1UL, &key->y, + LTC_ASN1_INTEGER, 1UL, &key->x, + LTC_ASN1_EOL, 0UL, NULL); } else { return der_encode_sequence_multi(out, outlen, LTC_ASN1_BIT_STRING, 1UL, flags, diff --git a/libtomcrypt/pk/dsa/dsa_import.c b/libtomcrypt/pk/dsa/dsa_import.c index 3172d5d69e6..88e74f59e52 100644 --- a/libtomcrypt/pk/dsa/dsa_import.c +++ b/libtomcrypt/pk/dsa/dsa_import.c @@ -28,6 +28,7 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key) { unsigned char flags[1]; int err; + unsigned long zero = 0; LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); @@ -41,22 +42,21 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key) if ((err = der_decode_sequence_multi(in, inlen, LTC_ASN1_BIT_STRING, 1UL, flags, LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { - goto error; - } - - if (flags[0] == 1) { + /* private key */ if ((err = der_decode_sequence_multi(in, inlen, - LTC_ASN1_BIT_STRING, 1UL, flags, - LTC_ASN1_INTEGER, 1UL, &key->g, - LTC_ASN1_INTEGER, 1UL, &key->p, - LTC_ASN1_INTEGER, 1UL, &key->q, - LTC_ASN1_INTEGER, 1UL, &key->y, - LTC_ASN1_INTEGER, 1UL, &key->x, - LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { + LTC_ASN1_SHORT_INTEGER, 1UL, &zero, + LTC_ASN1_INTEGER, 1UL, &key->p, + LTC_ASN1_INTEGER, 1UL, &key->q, + LTC_ASN1_INTEGER, 1UL, &key->g, + LTC_ASN1_INTEGER, 1UL, &key->y, + LTC_ASN1_INTEGER, 1UL, &key->x, + LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto error; } key->type = PK_PRIVATE; - } else { + + } else { /* public */ + if ((err = der_decode_sequence_multi(in, inlen, LTC_ASN1_BIT_STRING, 1UL, flags, LTC_ASN1_INTEGER, 1UL, &key->g, |