diff options
author | Richard Levitte <levitte@openssl.org> | 2002-01-02 16:55:35 +0000 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2002-01-02 16:55:35 +0000 |
commit | 6f9079fd505c28961049a732e33e662530bdad21 (patch) | |
tree | 4c5850b3d621185192a0755809601d9e4ab72291 /crypto/evp | |
parent | c938563a81d48e1d23bddcf9283d4961794db132 (diff) |
Because Rijndael is more known as AES, use crypto/aes instead of
crypto/rijndael. Additionally, I applied the AES integration patch
from Stephen Sprunk <stephen@sprunk.org> and fiddled it to work
properly with the normal EVP constructs (and incidently work the same
way as all other symmetric cipher implementations).
This results in an API that looks a lot like the rest of the OpenSSL
cipher suite.
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/Makefile.ssl | 18 | ||||
-rw-r--r-- | crypto/evp/e_aes.c | 129 |
2 files changed, 51 insertions, 96 deletions
diff --git a/crypto/evp/Makefile.ssl b/crypto/evp/Makefile.ssl index d22bdf3b1f..b467f90ceb 100644 --- a/crypto/evp/Makefile.ssl +++ b/crypto/evp/Makefile.ssl @@ -186,15 +186,15 @@ digest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h digest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h digest.o: ../../include/openssl/ui.h ../cryptlib.h digest.c -e_aes.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h -e_aes.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h -e_aes.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h -e_aes.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -e_aes.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -e_aes.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -e_aes.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rd_fst.h -e_aes.o: ../../include/openssl/rijndael.h ../../include/openssl/safestack.h -e_aes.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h e_aes.c +e_aes.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h +e_aes.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +e_aes.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h +e_aes.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_aes.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h +e_aes.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_aes.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +e_aes.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +e_aes.o: ../../include/openssl/symhacks.h e_aes.c evp_locl.h e_bf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h e_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h e_bf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index 51a51a7bbe..9d91533a9e 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -53,102 +53,57 @@ #include <openssl/err.h> #include <string.h> #include <assert.h> -#include <openssl/rijndael.h> +#include <openssl/aes.h> +#include "evp_locl.h" -static int aes_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, +static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc); -static int aes_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, unsigned int inl); -static int aes_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, unsigned int inl); -#define IMPLEMENT_AES_CIPHER(name, ciph_func, keylen, ivlen, mode) \ -static const EVP_CIPHER name##_cipher_st = \ - { \ - NID_##name, \ - 16,keylen,ivlen, \ - mode, \ - aes_init, \ - ciph_func, \ - NULL, \ - sizeof(RIJNDAEL_KEY), \ - EVP_CIPHER_set_asn1_iv, \ - EVP_CIPHER_get_asn1_iv, \ - NULL, \ - NULL \ - }; \ -const EVP_CIPHER * EVP_##name(void) \ - { \ - return &name##_cipher_st; \ - } +typedef struct + { + AES_KEY ks; + } EVP_AES_KEY; -IMPLEMENT_AES_CIPHER(aes_128_ecb, aes_ecb, 16, 0, EVP_CIPH_ECB_MODE) -IMPLEMENT_AES_CIPHER(aes_192_ecb, aes_ecb, 24, 0, EVP_CIPH_ECB_MODE) -IMPLEMENT_AES_CIPHER(aes_256_ecb, aes_ecb, 32, 0, EVP_CIPH_ECB_MODE) +#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx) -IMPLEMENT_AES_CIPHER(aes_128_cbc, aes_cbc, 16, 16, EVP_CIPH_CBC_MODE) -IMPLEMENT_AES_CIPHER(aes_192_cbc, aes_cbc, 24, 16, EVP_CIPH_CBC_MODE) -IMPLEMENT_AES_CIPHER(aes_256_cbc, aes_cbc, 32, 16, EVP_CIPH_CBC_MODE) +#define IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(cname, ksched, cprefix, kstruct, \ + nid, block_size, key_len, iv_len, flags, \ + init_key, cleanup, set_asn1, get_asn1, ctrl) \ +BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \ +BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \ +BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \ + init_key, cleanup, set_asn1, get_asn1, ctrl) \ +BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, 0, flags, \ + init_key, cleanup, set_asn1, get_asn1, ctrl) -static int aes_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) - { - RIJNDAEL_KEY *k=ctx->cipher_data; - if (enc) - k->rounds = rijndaelKeySetupEnc(k->rd_key, key, ctx->key_len * 8); - else - k->rounds = rijndaelKeySetupDec(k->rd_key, key, ctx->key_len * 8); +IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(aes_128, ks, AES, EVP_AES_KEY, + NID_aes_128, 16, 16, 16, + 0, aes_init_key, NULL, + EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, + NULL) +IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(aes_192, ks, AES, EVP_AES_KEY, + NID_aes_192, 16, 24, 16, + 0, aes_init_key, NULL, + EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, + NULL) +IMPLEMENT_BLOCK_CIPHER_def_ecb_cbc(aes_256, ks, AES, EVP_AES_KEY, + NID_aes_256, 16, 32, 16, + 0, aes_init_key, NULL, + EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, + NULL) - return 1; - } +static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, + const unsigned char *iv, int enc) { -static int aes_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, unsigned int inl) - { - RIJNDAEL_KEY *k=ctx->cipher_data; - while(inl > 0) - { - if(ctx->encrypt) - rijndaelEncrypt(k->rd_key,k->rounds, in, out); - else - rijndaelDecrypt(k->rd_key,k->rounds, in, out); - inl-=16; - in+=16; - out+=16; - } - assert(inl == 0); + if (enc) + AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data); + else + AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data); return 1; - } +} -static int aes_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, unsigned int inl) - { - int n; - unsigned char tmp[16]; - RIJNDAEL_KEY *k=ctx->cipher_data; - while(inl > 0) - { - if(ctx->encrypt) - { - for(n=0 ; n < 16 ; n++) - tmp[n] = in[n] ^ ctx->iv[n]; - rijndaelEncrypt(k->rd_key,k->rounds, tmp, out); - memcpy(ctx->iv,out,16); - } - else - { - memcpy(tmp, in, 16); - rijndaelDecrypt(k->rd_key,k->rounds, in, out); - for(n=0 ; n < 16 ; n++) - out[n] ^= ctx->iv[n]; - memcpy(ctx->iv,tmp,16); - } - inl-=16; - in+=16; - out+=16; - } - assert(inl == 0); - return 1; - } #endif |