diff options
Diffstat (limited to 'libtomcrypt/src/pk/katja')
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_decrypt_key.c | 22 | ||||
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_encrypt_key.c | 30 | ||||
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_export.c | 42 | ||||
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_exptmod.c | 26 | ||||
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_free.c | 12 | ||||
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_import.c | 40 | ||||
-rw-r--r-- | libtomcrypt/src/pk/katja/katja_make_key.c | 18 |
7 files changed, 88 insertions, 102 deletions
diff --git a/libtomcrypt/src/pk/katja/katja_decrypt_key.c b/libtomcrypt/src/pk/katja/katja_decrypt_key.c index e8819d9..72009b0 100644 --- a/libtomcrypt/src/pk/katja/katja_decrypt_key.c +++ b/libtomcrypt/src/pk/katja/katja_decrypt_key.c @@ -5,20 +5,18 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_decrypt_key.c - Katja LTC_PKCS #1 OAEP Decryption, Tom St Denis -*/ + Katja PKCS #1 OAEP Decryption, Tom St Denis +*/ -#ifdef MKAT +#ifdef LTC_MKAT /** - (LTC_PKCS #1 v2.0) decrypt then OAEP depad + (PKCS #1 v2.0) decrypt then OAEP depad @param in The ciphertext @param inlen The length of the ciphertext (octets) @param out [out] The plaintext @@ -31,7 +29,7 @@ @return CRYPT_OK if succcessul (even if invalid) */ int katja_decrypt_key(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, + unsigned char *out, unsigned long *outlen, const unsigned char *lparam, unsigned long lparamlen, int hash_idx, int *stat, katja_key *key) @@ -39,7 +37,7 @@ int katja_decrypt_key(const unsigned char *in, unsigned long inlen, unsigned long modulus_bitlen, modulus_bytelen, x; int err; unsigned char *tmp; - + LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); @@ -52,7 +50,7 @@ int katja_decrypt_key(const unsigned char *in, unsigned long inlen, if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { return err; } - + /* get modulus len in bits */ modulus_bitlen = mp_count_bits( (key->N)); @@ -100,6 +98,6 @@ int katja_decrypt_key(const unsigned char *in, unsigned long inlen, -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/pk/katja/katja_encrypt_key.c b/libtomcrypt/src/pk/katja/katja_encrypt_key.c index ef59e92..9ed72fb 100644 --- a/libtomcrypt/src/pk/katja/katja_encrypt_key.c +++ b/libtomcrypt/src/pk/katja/katja_encrypt_key.c @@ -5,20 +5,18 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_encrypt_key.c - Katja LTC_PKCS-style OAEP encryption, Tom St Denis -*/ + Katja PKCS-style OAEP encryption, Tom St Denis +*/ -#ifdef MKAT +#ifdef LTC_MKAT /** - (LTC_PKCS #1 v2.0) OAEP pad then encrypt + (PKCS #1 v2.0) OAEP pad then encrypt @param in The plaintext @param inlen The length of the plaintext (octets) @param out [out] The ciphertext @@ -30,7 +28,7 @@ @param hash_idx The index of the desired hash @param key The Katja key to encrypt to @return CRYPT_OK if successful -*/ +*/ int katja_encrypt_key(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, const unsigned char *lparam, unsigned long lparamlen, @@ -38,12 +36,12 @@ int katja_encrypt_key(const unsigned char *in, unsigned long inlen, { unsigned long modulus_bitlen, modulus_bytelen, x; int err; - + LTC_ARGCHK(in != NULL); LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); - + /* valid prng and hash ? */ if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) { return err; @@ -51,7 +49,7 @@ int katja_encrypt_key(const unsigned char *in, unsigned long inlen, if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { return err; } - + /* get modulus len in bits */ modulus_bitlen = mp_count_bits((key->N)); @@ -70,11 +68,11 @@ int katja_encrypt_key(const unsigned char *in, unsigned long inlen, /* OAEP pad the key */ x = *outlen; - if ((err = pkcs_1_oaep_encode(in, inlen, lparam, - lparamlen, modulus_bitlen, prng, prng_idx, hash_idx, + if ((err = pkcs_1_oaep_encode(in, inlen, lparam, + lparamlen, modulus_bitlen, prng, prng_idx, hash_idx, out, &x)) != CRYPT_OK) { return err; - } + } /* Katja exptmod the OAEP pad */ return katja_exptmod(out, x, out, outlen, PK_PUBLIC, key); @@ -82,6 +80,6 @@ int katja_encrypt_key(const unsigned char *in, unsigned long inlen, #endif /* LTC_MRSA */ -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/pk/katja/katja_export.c b/libtomcrypt/src/pk/katja/katja_export.c index 5f4d327..0412e65 100644 --- a/libtomcrypt/src/pk/katja/katja_export.c +++ b/libtomcrypt/src/pk/katja/katja_export.c @@ -5,17 +5,15 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_export.c - Export Katja LTC_PKCS-style keys, Tom St Denis -*/ + Export Katja PKCS-style keys, Tom St Denis +*/ -#ifdef MKAT +#ifdef LTC_MKAT /** This will export either an KatjaPublicKey or KatjaPrivateKey @@ -24,7 +22,7 @@ @param type The type of exported key (PK_PRIVATE or PK_PUBLIC) @param key The Katja key to export @return CRYPT_OK if successful -*/ +*/ int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key) { int err; @@ -41,35 +39,35 @@ int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key if (type == PK_PRIVATE) { /* private key */ - /* output is + /* output is Version, n, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p, pq */ - if ((err = der_encode_sequence_multi(out, outlen, - LTC_ASN1_SHORT_INTEGER, 1UL, &zero, - LTC_ASN1_INTEGER, 1UL, key->N, - LTC_ASN1_INTEGER, 1UL, key->d, - LTC_ASN1_INTEGER, 1UL, key->p, - LTC_ASN1_INTEGER, 1UL, key->q, + if ((err = der_encode_sequence_multi(out, outlen, + LTC_ASN1_SHORT_INTEGER, 1UL, &zero, + LTC_ASN1_INTEGER, 1UL, key->N, + LTC_ASN1_INTEGER, 1UL, key->d, + LTC_ASN1_INTEGER, 1UL, key->p, + LTC_ASN1_INTEGER, 1UL, key->q, LTC_ASN1_INTEGER, 1UL, key->dP, - LTC_ASN1_INTEGER, 1UL, key->dQ, - LTC_ASN1_INTEGER, 1UL, key->qP, - LTC_ASN1_INTEGER, 1UL, key->pq, + LTC_ASN1_INTEGER, 1UL, key->dQ, + LTC_ASN1_INTEGER, 1UL, key->qP, + LTC_ASN1_INTEGER, 1UL, key->pq, LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { return err; } - + /* clear zero and return */ return CRYPT_OK; } else { /* public key */ - return der_encode_sequence_multi(out, outlen, - LTC_ASN1_INTEGER, 1UL, key->N, + return der_encode_sequence_multi(out, outlen, + LTC_ASN1_INTEGER, 1UL, key->N, LTC_ASN1_EOL, 0UL, NULL); } } #endif /* LTC_MRSA */ -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/pk/katja/katja_exptmod.c b/libtomcrypt/src/pk/katja/katja_exptmod.c index 5df8908..afc847f 100644 --- a/libtomcrypt/src/pk/katja/katja_exptmod.c +++ b/libtomcrypt/src/pk/katja/katja_exptmod.c @@ -5,28 +5,26 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_exptmod.c - Katja LTC_PKCS-style exptmod, Tom St Denis -*/ + Katja PKCS-style exptmod, Tom St Denis +*/ -#ifdef MKAT +#ifdef LTC_MKAT -/** - Compute an RSA modular exponentiation +/** + Compute an RSA modular exponentiation @param in The input data to send into RSA @param inlen The length of the input (octets) - @param out [out] The destination + @param out [out] The destination @param outlen [in/out] The max size and resulting size of the output @param which Which exponent to use, e.g. PK_PRIVATE or PK_PUBLIC - @param key The RSA key to use + @param key The RSA key to use @return CRYPT_OK if successful -*/ +*/ int katja_exptmod(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, int which, katja_key *key) @@ -39,7 +37,7 @@ int katja_exptmod(const unsigned char *in, unsigned long inlen, LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); - + /* is the key of the right type for the operation? */ if (which == PK_PRIVATE && (key->type != PK_PRIVATE)) { return CRYPT_PK_NOT_PRIVATE; @@ -110,6 +108,6 @@ done: #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/pk/katja/katja_free.c b/libtomcrypt/src/pk/katja/katja_free.c index c5a46af..117bbf4 100644 --- a/libtomcrypt/src/pk/katja/katja_free.c +++ b/libtomcrypt/src/pk/katja/katja_free.c @@ -5,17 +5,15 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_free.c Free an Katja key, Tom St Denis -*/ +*/ -#ifdef MKAT +#ifdef LTC_MKAT /** Free an Katja key from memory @@ -30,6 +28,6 @@ void katja_free(katja_key *key) #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/pk/katja/katja_import.c b/libtomcrypt/src/pk/katja/katja_import.c index 425f498..98357c0 100644 --- a/libtomcrypt/src/pk/katja/katja_import.c +++ b/libtomcrypt/src/pk/katja/katja_import.c @@ -5,20 +5,18 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_import.c - Import a LTC_PKCS-style Katja key, Tom St Denis -*/ + Import a PKCS-style Katja key, Tom St Denis +*/ -#ifdef MKAT +#ifdef LTC_MKAT /** - Import an KatjaPublicKey or KatjaPrivateKey [two-prime only, only support >= 1024-bit keys, defined in LTC_PKCS #1 v2.1] + Import an KatjaPublicKey or KatjaPrivateKey [two-prime only, only support >= 1024-bit keys, defined in PKCS #1 v2.1] @param in The packet to import from @param inlen It's length (octets) @param key [out] Destination for newly imported key @@ -34,29 +32,29 @@ int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key) LTC_ARGCHK(ltc_mp.name != NULL); /* init key */ - if ((err = mp_init_multi(&zero, &key->d, &key->N, &key->dQ, + if ((err = mp_init_multi(&zero, &key->d, &key->N, &key->dQ, &key->dP, &key->qP, &key->p, &key->q, &key->pq, NULL)) != CRYPT_OK) { return err; } - if ((err = der_decode_sequence_multi(in, inlen, - LTC_ASN1_INTEGER, 1UL, key->N, + if ((err = der_decode_sequence_multi(in, inlen, + LTC_ASN1_INTEGER, 1UL, key->N, LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto LBL_ERR; } if (mp_cmp_d(key->N, 0) == LTC_MP_EQ) { /* it's a private key */ - if ((err = der_decode_sequence_multi(in, inlen, - LTC_ASN1_INTEGER, 1UL, zero, - LTC_ASN1_INTEGER, 1UL, key->N, - LTC_ASN1_INTEGER, 1UL, key->d, - LTC_ASN1_INTEGER, 1UL, key->p, - LTC_ASN1_INTEGER, 1UL, key->q, + if ((err = der_decode_sequence_multi(in, inlen, + LTC_ASN1_INTEGER, 1UL, zero, + LTC_ASN1_INTEGER, 1UL, key->N, + LTC_ASN1_INTEGER, 1UL, key->d, + LTC_ASN1_INTEGER, 1UL, key->p, + LTC_ASN1_INTEGER, 1UL, key->q, LTC_ASN1_INTEGER, 1UL, key->dP, - LTC_ASN1_INTEGER, 1UL, key->dQ, - LTC_ASN1_INTEGER, 1UL, key->qP, - LTC_ASN1_INTEGER, 1UL, key->pq, + LTC_ASN1_INTEGER, 1UL, key->dQ, + LTC_ASN1_INTEGER, 1UL, key->qP, + LTC_ASN1_INTEGER, 1UL, key->pq, LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { goto LBL_ERR; } @@ -76,6 +74,6 @@ LBL_ERR: #endif /* LTC_MRSA */ -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/pk/katja/katja_make_key.c b/libtomcrypt/src/pk/katja/katja_make_key.c index eec8e98..6f83bcc 100644 --- a/libtomcrypt/src/pk/katja/katja_make_key.c +++ b/libtomcrypt/src/pk/katja/katja_make_key.c @@ -5,19 +5,17 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" /** @file katja_make_key.c Katja key generation, Tom St Denis -*/ +*/ -#ifdef MKAT +#ifdef LTC_MKAT -/** +/** Create a Katja key @param prng An active PRNG state @param wprng The index of the PRNG desired @@ -29,7 +27,7 @@ int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key) { void *p, *q, *tmp1, *tmp2; int err; - + LTC_ARGCHK(key != NULL); LTC_ARGCHK(ltc_mp.name != NULL); @@ -68,7 +66,7 @@ int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key) if ((err = mp_copy( p, key->p)) != CRYPT_OK) { goto error2; } if ((err = mp_copy( q, key->q)) != CRYPT_OK) { goto error2; } if ((err = mp_mul(key->p, key->q, key->pq)) != CRYPT_OK) { goto error2; } /* tmp1 = pq */ - if ((err = mp_mul(key->pq, key->p, key->N)) != CRYPT_OK) { goto error2; } /* N = p^2q */ + if ((err = mp_mul(key->pq, key->p, key->N)) != CRYPT_OK) { goto error2; } /* N = p^2q */ if ((err = mp_sub_d( p, 1, tmp1)) != CRYPT_OK) { goto error2; } /* tmp1 = q-1 */ if ((err = mp_sub_d( q, 1, tmp2)) != CRYPT_OK) { goto error2; } /* tmp2 = p-1 */ if ((err = mp_lcm(tmp1, tmp2, key->d)) != CRYPT_OK) { goto error2; } /* tmp1 = lcd(p-1,q-1) */ @@ -96,6 +94,6 @@ done: #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ |