diff options
| author | markus <> | 2003-05-12 02:18:40 +0000 |
|---|---|---|
| committer | markus <> | 2003-05-12 02:18:40 +0000 |
| commit | d4fcd82bb7f6d603bd61e19a81ba97337b89dfca (patch) | |
| tree | d52e3a0f1f08f65ad283027e560e17ed0d720462 /src/lib/libcrypto/aes | |
| parent | 582bbd139cd2afd58d10dc051c5b0b989b441074 (diff) | |
| download | openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.gz openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.bz2 openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.zip | |
merge 0.9.7b with local changes; crank majors for libssl/libcrypto
Diffstat (limited to 'src/lib/libcrypto/aes')
| -rw-r--r-- | src/lib/libcrypto/aes/Makefile.ssl | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes.h | 9 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_cbc.c | 58 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_cfb.c | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_core.c | 12 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_ctr.c | 21 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_ecb.c | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_locl.h | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/aes/aes_ofb.c | 6 |
9 files changed, 91 insertions, 31 deletions
diff --git a/src/lib/libcrypto/aes/Makefile.ssl b/src/lib/libcrypto/aes/Makefile.ssl index 9358802a2e..f353aeb697 100644 --- a/src/lib/libcrypto/aes/Makefile.ssl +++ b/src/lib/libcrypto/aes/Makefile.ssl | |||
| @@ -75,7 +75,7 @@ lint: | |||
| 75 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 75 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
| 76 | 76 | ||
| 77 | depend: | 77 | depend: |
| 78 | $(MAKEDEPEND) $(CFLAG) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) | 78 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) |
| 79 | 79 | ||
| 80 | dclean: | 80 | dclean: |
| 81 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 81 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
diff --git a/src/lib/libcrypto/aes/aes.h b/src/lib/libcrypto/aes/aes.h index e8da921ec5..8294a41a3a 100644 --- a/src/lib/libcrypto/aes/aes.h +++ b/src/lib/libcrypto/aes/aes.h | |||
| @@ -56,8 +56,9 @@ | |||
| 56 | #error AES is disabled. | 56 | #error AES is disabled. |
| 57 | #endif | 57 | #endif |
| 58 | 58 | ||
| 59 | static const int AES_DECRYPT = 0; | 59 | #define AES_ENCRYPT 1 |
| 60 | static const int AES_ENCRYPT = 1; | 60 | #define AES_DECRYPT 0 |
| 61 | |||
| 61 | /* Because array size can't be a const in C, the following two are macros. | 62 | /* Because array size can't be a const in C, the following two are macros. |
| 62 | Both sizes are in bytes. */ | 63 | Both sizes are in bytes. */ |
| 63 | #define AES_MAXNR 14 | 64 | #define AES_MAXNR 14 |
| @@ -99,7 +100,9 @@ void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, | |||
| 99 | unsigned char *ivec, int *num); | 100 | unsigned char *ivec, int *num); |
| 100 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, | 101 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, |
| 101 | const unsigned long length, const AES_KEY *key, | 102 | const unsigned long length, const AES_KEY *key, |
| 102 | unsigned char *counter, unsigned int *num); | 103 | unsigned char counter[AES_BLOCK_SIZE], |
| 104 | unsigned char ecount_buf[AES_BLOCK_SIZE], | ||
| 105 | unsigned int *num); | ||
| 103 | 106 | ||
| 104 | 107 | ||
| 105 | #ifdef __cplusplus | 108 | #ifdef __cplusplus |
diff --git a/src/lib/libcrypto/aes/aes_cbc.c b/src/lib/libcrypto/aes/aes_cbc.c index 3dfd7aba2a..de438306b1 100644 --- a/src/lib/libcrypto/aes/aes_cbc.c +++ b/src/lib/libcrypto/aes/aes_cbc.c | |||
| @@ -49,7 +49,13 @@ | |||
| 49 | * | 49 | * |
| 50 | */ | 50 | */ |
| 51 | 51 | ||
| 52 | #ifndef AES_DEBUG | ||
| 53 | # ifndef NDEBUG | ||
| 54 | # define NDEBUG | ||
| 55 | # endif | ||
| 56 | #endif | ||
| 52 | #include <assert.h> | 57 | #include <assert.h> |
| 58 | |||
| 53 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
| 54 | #include "aes_locl.h" | 60 | #include "aes_locl.h" |
| 55 | 61 | ||
| @@ -57,33 +63,49 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, | |||
| 57 | const unsigned long length, const AES_KEY *key, | 63 | const unsigned long length, const AES_KEY *key, |
| 58 | unsigned char *ivec, const int enc) { | 64 | unsigned char *ivec, const int enc) { |
| 59 | 65 | ||
| 60 | int n; | 66 | unsigned long n; |
| 61 | unsigned long len = length; | 67 | unsigned long len = length; |
| 62 | unsigned char tmp[16]; | 68 | unsigned char tmp[AES_BLOCK_SIZE]; |
| 63 | 69 | ||
| 64 | assert(in && out && key && ivec); | 70 | assert(in && out && key && ivec); |
| 65 | assert(length % AES_BLOCK_SIZE == 0); | ||
| 66 | assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); | 71 | assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); |
| 67 | 72 | ||
| 68 | if (AES_ENCRYPT == enc) | 73 | if (AES_ENCRYPT == enc) { |
| 69 | while (len > 0) { | 74 | while (len >= AES_BLOCK_SIZE) { |
| 70 | for(n=0; n < 16; ++n) | 75 | for(n=0; n < sizeof tmp; ++n) |
| 71 | tmp[n] = in[n] ^ ivec[n]; | 76 | tmp[n] = in[n] ^ ivec[n]; |
| 72 | AES_encrypt(tmp, out, key); | 77 | AES_encrypt(tmp, out, key); |
| 73 | memcpy(ivec, out, 16); | 78 | memcpy(ivec, out, AES_BLOCK_SIZE); |
| 74 | len -= 16; | 79 | len -= AES_BLOCK_SIZE; |
| 75 | in += 16; | 80 | in += AES_BLOCK_SIZE; |
| 76 | out += 16; | 81 | out += AES_BLOCK_SIZE; |
| 77 | } | 82 | } |
| 78 | else | 83 | if (len) { |
| 79 | while (len > 0) { | 84 | for(n=0; n < len; ++n) |
| 80 | memcpy(tmp, in, 16); | 85 | tmp[n] = in[n] ^ ivec[n]; |
| 86 | for(n=len; n < AES_BLOCK_SIZE; ++n) | ||
| 87 | tmp[n] = ivec[n]; | ||
| 88 | AES_encrypt(tmp, tmp, key); | ||
| 89 | memcpy(out, tmp, len); | ||
| 90 | memcpy(ivec, tmp, sizeof tmp); | ||
| 91 | } | ||
| 92 | } else { | ||
| 93 | while (len >= AES_BLOCK_SIZE) { | ||
| 94 | memcpy(tmp, in, sizeof tmp); | ||
| 81 | AES_decrypt(in, out, key); | 95 | AES_decrypt(in, out, key); |
| 82 | for(n=0; n < 16; ++n) | 96 | for(n=0; n < AES_BLOCK_SIZE; ++n) |
| 83 | out[n] ^= ivec[n]; | 97 | out[n] ^= ivec[n]; |
| 84 | memcpy(ivec, tmp, 16); | 98 | memcpy(ivec, tmp, AES_BLOCK_SIZE); |
| 85 | len -= 16; | 99 | len -= AES_BLOCK_SIZE; |
| 86 | in += 16; | 100 | in += AES_BLOCK_SIZE; |
| 87 | out += 16; | 101 | out += AES_BLOCK_SIZE; |
| 88 | } | 102 | } |
| 103 | if (len) { | ||
| 104 | memcpy(tmp, in, sizeof tmp); | ||
| 105 | AES_decrypt(tmp, tmp, key); | ||
| 106 | for(n=0; n < len; ++n) | ||
| 107 | out[n] ^= ivec[n]; | ||
| 108 | memcpy(ivec, tmp, sizeof tmp); | ||
| 109 | } | ||
| 110 | } | ||
| 89 | } | 111 | } |
diff --git a/src/lib/libcrypto/aes/aes_cfb.c b/src/lib/libcrypto/aes/aes_cfb.c index 41c2a5ec3d..9b569dda90 100644 --- a/src/lib/libcrypto/aes/aes_cfb.c +++ b/src/lib/libcrypto/aes/aes_cfb.c | |||
| @@ -105,7 +105,13 @@ | |||
| 105 | * [including the GNU Public Licence.] | 105 | * [including the GNU Public Licence.] |
| 106 | */ | 106 | */ |
| 107 | 107 | ||
| 108 | #ifndef AES_DEBUG | ||
| 109 | # ifndef NDEBUG | ||
| 110 | # define NDEBUG | ||
| 111 | # endif | ||
| 112 | #endif | ||
| 108 | #include <assert.h> | 113 | #include <assert.h> |
| 114 | |||
| 109 | #include <openssl/aes.h> | 115 | #include <openssl/aes.h> |
| 110 | #include "aes_locl.h" | 116 | #include "aes_locl.h" |
| 111 | 117 | ||
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c index 937988dd8c..2f41a825f8 100644 --- a/src/lib/libcrypto/aes/aes_core.c +++ b/src/lib/libcrypto/aes/aes_core.c | |||
| @@ -28,7 +28,13 @@ | |||
| 28 | /* Note: rewritten a little bit to provide error control and an OpenSSL- | 28 | /* Note: rewritten a little bit to provide error control and an OpenSSL- |
| 29 | compatible API */ | 29 | compatible API */ |
| 30 | 30 | ||
| 31 | #ifndef AES_DEBUG | ||
| 32 | # ifndef NDEBUG | ||
| 33 | # define NDEBUG | ||
| 34 | # endif | ||
| 35 | #endif | ||
| 31 | #include <assert.h> | 36 | #include <assert.h> |
| 37 | |||
| 32 | #include <stdlib.h> | 38 | #include <stdlib.h> |
| 33 | #include <openssl/aes.h> | 39 | #include <openssl/aes.h> |
| 34 | #include "aes_locl.h" | 40 | #include "aes_locl.h" |
| @@ -744,7 +750,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits, | |||
| 744 | rk[2] = GETU32(userKey + 8); | 750 | rk[2] = GETU32(userKey + 8); |
| 745 | rk[3] = GETU32(userKey + 12); | 751 | rk[3] = GETU32(userKey + 12); |
| 746 | if (bits == 128) { | 752 | if (bits == 128) { |
| 747 | for (;;) { | 753 | while (1) { |
| 748 | temp = rk[3]; | 754 | temp = rk[3]; |
| 749 | rk[4] = rk[0] ^ | 755 | rk[4] = rk[0] ^ |
| 750 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ | 756 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ |
| @@ -764,7 +770,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits, | |||
| 764 | rk[4] = GETU32(userKey + 16); | 770 | rk[4] = GETU32(userKey + 16); |
| 765 | rk[5] = GETU32(userKey + 20); | 771 | rk[5] = GETU32(userKey + 20); |
| 766 | if (bits == 192) { | 772 | if (bits == 192) { |
| 767 | for (;;) { | 773 | while (1) { |
| 768 | temp = rk[ 5]; | 774 | temp = rk[ 5]; |
| 769 | rk[ 6] = rk[ 0] ^ | 775 | rk[ 6] = rk[ 0] ^ |
| 770 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ | 776 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ |
| @@ -786,7 +792,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits, | |||
| 786 | rk[6] = GETU32(userKey + 24); | 792 | rk[6] = GETU32(userKey + 24); |
| 787 | rk[7] = GETU32(userKey + 28); | 793 | rk[7] = GETU32(userKey + 28); |
| 788 | if (bits == 256) { | 794 | if (bits == 256) { |
| 789 | for (;;) { | 795 | while (1) { |
| 790 | temp = rk[ 7]; | 796 | temp = rk[ 7]; |
| 791 | rk[ 8] = rk[ 0] ^ | 797 | rk[ 8] = rk[ 0] ^ |
| 792 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ | 798 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ |
diff --git a/src/lib/libcrypto/aes/aes_ctr.c b/src/lib/libcrypto/aes/aes_ctr.c index aea3db2092..59088499a0 100644 --- a/src/lib/libcrypto/aes/aes_ctr.c +++ b/src/lib/libcrypto/aes/aes_ctr.c | |||
| @@ -49,7 +49,13 @@ | |||
| 49 | * | 49 | * |
| 50 | */ | 50 | */ |
| 51 | 51 | ||
| 52 | #ifndef AES_DEBUG | ||
| 53 | # ifndef NDEBUG | ||
| 54 | # define NDEBUG | ||
| 55 | # endif | ||
| 56 | #endif | ||
| 52 | #include <assert.h> | 57 | #include <assert.h> |
| 58 | |||
| 53 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
| 54 | #include "aes_locl.h" | 60 | #include "aes_locl.h" |
| 55 | 61 | ||
| @@ -90,26 +96,31 @@ static void AES_ctr128_inc(unsigned char *counter) { | |||
| 90 | 96 | ||
| 91 | /* The input encrypted as though 128bit counter mode is being | 97 | /* The input encrypted as though 128bit counter mode is being |
| 92 | * used. The extra state information to record how much of the | 98 | * used. The extra state information to record how much of the |
| 93 | * 128bit block we have used is contained in *num; | 99 | * 128bit block we have used is contained in *num, and the |
| 100 | * encrypted counter is kept in ecount_buf. Both *num and | ||
| 101 | * ecount_buf must be initialised with zeros before the first | ||
| 102 | * call to AES_ctr128_encrypt(). | ||
| 94 | */ | 103 | */ |
| 95 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, | 104 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, |
| 96 | const unsigned long length, const AES_KEY *key, | 105 | const unsigned long length, const AES_KEY *key, |
| 97 | unsigned char *counter, unsigned int *num) { | 106 | unsigned char counter[AES_BLOCK_SIZE], |
| 107 | unsigned char ecount_buf[AES_BLOCK_SIZE], | ||
| 108 | unsigned int *num) { | ||
| 98 | 109 | ||
| 99 | unsigned int n; | 110 | unsigned int n; |
| 100 | unsigned long l=length; | 111 | unsigned long l=length; |
| 101 | unsigned char tmp[AES_BLOCK_SIZE]; | ||
| 102 | 112 | ||
| 103 | assert(in && out && key && counter && num); | 113 | assert(in && out && key && counter && num); |
| 114 | assert(*num < AES_BLOCK_SIZE); | ||
| 104 | 115 | ||
| 105 | n = *num; | 116 | n = *num; |
| 106 | 117 | ||
| 107 | while (l--) { | 118 | while (l--) { |
| 108 | if (n == 0) { | 119 | if (n == 0) { |
| 109 | AES_encrypt(counter, tmp, key); | 120 | AES_encrypt(counter, ecount_buf, key); |
| 110 | AES_ctr128_inc(counter); | 121 | AES_ctr128_inc(counter); |
| 111 | } | 122 | } |
| 112 | *(out++) = *(in++) ^ tmp[n]; | 123 | *(out++) = *(in++) ^ ecount_buf[n]; |
| 113 | n = (n+1) % AES_BLOCK_SIZE; | 124 | n = (n+1) % AES_BLOCK_SIZE; |
| 114 | } | 125 | } |
| 115 | 126 | ||
diff --git a/src/lib/libcrypto/aes/aes_ecb.c b/src/lib/libcrypto/aes/aes_ecb.c index 1cb2e07d3d..28aa561c2d 100644 --- a/src/lib/libcrypto/aes/aes_ecb.c +++ b/src/lib/libcrypto/aes/aes_ecb.c | |||
| @@ -49,7 +49,13 @@ | |||
| 49 | * | 49 | * |
| 50 | */ | 50 | */ |
| 51 | 51 | ||
| 52 | #ifndef AES_DEBUG | ||
| 53 | # ifndef NDEBUG | ||
| 54 | # define NDEBUG | ||
| 55 | # endif | ||
| 56 | #endif | ||
| 52 | #include <assert.h> | 57 | #include <assert.h> |
| 58 | |||
| 53 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
| 54 | #include "aes_locl.h" | 60 | #include "aes_locl.h" |
| 55 | 61 | ||
diff --git a/src/lib/libcrypto/aes/aes_locl.h b/src/lib/libcrypto/aes/aes_locl.h index 18fc2d0747..f290946058 100644 --- a/src/lib/libcrypto/aes/aes_locl.h +++ b/src/lib/libcrypto/aes/aes_locl.h | |||
| @@ -62,7 +62,7 @@ | |||
| 62 | #include <stdlib.h> | 62 | #include <stdlib.h> |
| 63 | #include <string.h> | 63 | #include <string.h> |
| 64 | 64 | ||
| 65 | #ifdef _MSC_VER | 65 | #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE) |
| 66 | # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) | 66 | # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) |
| 67 | # define GETU32(p) SWAP(*((u32 *)(p))) | 67 | # define GETU32(p) SWAP(*((u32 *)(p))) |
| 68 | # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } | 68 | # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } |
diff --git a/src/lib/libcrypto/aes/aes_ofb.c b/src/lib/libcrypto/aes/aes_ofb.c index e33bdaea28..f358bb39e2 100644 --- a/src/lib/libcrypto/aes/aes_ofb.c +++ b/src/lib/libcrypto/aes/aes_ofb.c | |||
| @@ -105,7 +105,13 @@ | |||
| 105 | * [including the GNU Public Licence.] | 105 | * [including the GNU Public Licence.] |
| 106 | */ | 106 | */ |
| 107 | 107 | ||
| 108 | #ifndef AES_DEBUG | ||
| 109 | # ifndef NDEBUG | ||
| 110 | # define NDEBUG | ||
| 111 | # endif | ||
| 112 | #endif | ||
| 108 | #include <assert.h> | 113 | #include <assert.h> |
| 114 | |||
| 109 | #include <openssl/aes.h> | 115 | #include <openssl/aes.h> |
| 110 | #include "aes_locl.h" | 116 | #include "aes_locl.h" |
| 111 | 117 | ||
