From 5d48a66a6a4bc27b54d32721f7183077489c2e5f Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 23 Dec 2008 11:33:01 +0000 Subject: Engage crypto/modes. --- crypto/seed/Makefile | 12 ++++---- crypto/seed/seed_cbc.c | 76 ++++---------------------------------------------- crypto/seed/seed_cfb.c | 34 ++-------------------- crypto/seed/seed_ofb.c | 18 ++---------- 4 files changed, 17 insertions(+), 123 deletions(-) (limited to 'crypto/seed') diff --git a/crypto/seed/Makefile b/crypto/seed/Makefile index 4babe82f74..4bc55e4916 100644 --- a/crypto/seed/Makefile +++ b/crypto/seed/Makefile @@ -81,17 +81,17 @@ seed.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h seed.o: ../../include/openssl/seed.h ../../include/openssl/stack.h seed.o: ../../include/openssl/symhacks.h seed.c seed_locl.h seed_cbc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -seed_cbc.o: ../../include/openssl/opensslconf.h +seed_cbc.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h seed_cbc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h seed_cbc.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h seed_cbc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -seed_cbc.o: seed_cbc.c seed_locl.h +seed_cbc.o: seed_cbc.c seed_cfb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -seed_cfb.o: ../../include/openssl/opensslconf.h +seed_cfb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h seed_cfb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h seed_cfb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h seed_cfb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -seed_cfb.o: seed_cfb.c seed_locl.h +seed_cfb.o: seed_cfb.c seed_ecb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h seed_ecb.o: ../../include/openssl/opensslconf.h seed_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h @@ -99,8 +99,8 @@ seed_ecb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h seed_ecb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h seed_ecb.o: seed_ecb.c seed_ofb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -seed_ofb.o: ../../include/openssl/opensslconf.h +seed_ofb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h seed_ofb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h seed_ofb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h seed_ofb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -seed_ofb.o: seed_locl.h seed_ofb.c +seed_ofb.o: seed_ofb.c diff --git a/crypto/seed/seed_cbc.c b/crypto/seed/seed_cbc.c index 4f718ccb44..6c3f9b527a 100644 --- a/crypto/seed/seed_cbc.c +++ b/crypto/seed/seed_cbc.c @@ -49,81 +49,15 @@ * */ -#include "seed_locl.h" -#include +#include +#include void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int enc) { - size_t n; - unsigned char tmp[SEED_BLOCK_SIZE]; - const unsigned char *iv = ivec; - if (enc) - { - while (len >= SEED_BLOCK_SIZE) - { - for (n = 0; n < SEED_BLOCK_SIZE; ++n) - out[n] = in[n] ^ iv[n]; - SEED_encrypt(out, out, ks); - iv = out; - len -= SEED_BLOCK_SIZE; - in += SEED_BLOCK_SIZE; - out += SEED_BLOCK_SIZE; - } - if (len) - { - for (n = 0; n < len; ++n) - out[n] = in[n] ^ iv[n]; - for (n = len; n < SEED_BLOCK_SIZE; ++n) - out[n] = iv[n]; - SEED_encrypt(out, out, ks); - iv = out; - } - memcpy(ivec, iv, SEED_BLOCK_SIZE); - } - else if (in != out) /* decrypt */ - { - while (len >= SEED_BLOCK_SIZE) - { - SEED_decrypt(in, out, ks); - for (n = 0; n < SEED_BLOCK_SIZE; ++n) - out[n] ^= iv[n]; - iv = in; - len -= SEED_BLOCK_SIZE; - in += SEED_BLOCK_SIZE; - out += SEED_BLOCK_SIZE; - } - if (len) - { - SEED_decrypt(in, tmp, ks); - for (n = 0; n < len; ++n) - out[n] = tmp[n] ^ iv[n]; - iv = in; - } - memcpy(ivec, iv, SEED_BLOCK_SIZE); - } - else /* decrypt, overlap */ - { - while (len >= SEED_BLOCK_SIZE) - { - memcpy(tmp, in, SEED_BLOCK_SIZE); - SEED_decrypt(in, out, ks); - for (n = 0; n < SEED_BLOCK_SIZE; ++n) - out[n] ^= ivec[n]; - memcpy(ivec, tmp, SEED_BLOCK_SIZE); - len -= SEED_BLOCK_SIZE; - in += SEED_BLOCK_SIZE; - out += SEED_BLOCK_SIZE; - } - if (len) - { - memcpy(tmp, in, SEED_BLOCK_SIZE); - SEED_decrypt(tmp, tmp, ks); - for (n = 0; n < len; ++n) - out[n] = tmp[n] ^ ivec[n]; - memcpy(ivec, tmp, SEED_BLOCK_SIZE); - } - } + CRYPTO_cbc128_encrypt(in,out,len,ks,ivec,(block128_f)SEED_encrypt); + else + CRYPTO_cbc128_decrypt(in,out,len,ks,ivec,(block128_f)SEED_decrypt); } diff --git a/crypto/seed/seed_cfb.c b/crypto/seed/seed_cfb.c index 07d878a788..694597dd06 100644 --- a/crypto/seed/seed_cfb.c +++ b/crypto/seed/seed_cfb.c @@ -105,40 +105,12 @@ * [including the GNU Public Licence.] */ -#include "seed_locl.h" -#include +#include +#include void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int *num, int enc) { - int n; - unsigned char c; - - n = *num; - - if (enc) - { - while (len--) - { - if (n == 0) - SEED_encrypt(ivec, ivec, ks); - ivec[n] = *(out++) = *(in++) ^ ivec[n]; - n = (n+1) % SEED_BLOCK_SIZE; - } - } - else - { - while (len--) - { - if (n == 0) - SEED_encrypt(ivec, ivec, ks); - c = *(in); - *(out++) = *(in++) ^ ivec[n]; - ivec[n] = c; - n = (n+1) % SEED_BLOCK_SIZE; - } - } - - *num = n; + CRYPTO_cfb128_encrypt(in,out,len,ks,ivec,num,enc,(block128_f)SEED_encrypt); } diff --git a/crypto/seed/seed_ofb.c b/crypto/seed/seed_ofb.c index e2f3f57a38..3c8ba33bb9 100644 --- a/crypto/seed/seed_ofb.c +++ b/crypto/seed/seed_ofb.c @@ -105,24 +105,12 @@ * [including the GNU Public Licence.] */ -#include "seed_locl.h" -#include +#include +#include void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int *num) { - int n; - - n = *num; - - while (len--) - { - if (n == 0) - SEED_encrypt(ivec, ivec, ks); - *(out++) = *(in++) ^ ivec[n]; - n = (n+1) % SEED_BLOCK_SIZE; - } - - *num = n; + CRYPTO_ofb128_encrypt(in,out,len,ks,ivec,num,(block128_f)SEED_encrypt); } -- cgit v1.2.3