summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/aes/aes_cbc.c
diff options
context:
space:
mode:
authormarkus <>2003-05-12 02:18:40 +0000
committermarkus <>2003-05-12 02:18:40 +0000
commitd4fcd82bb7f6d603bd61e19a81ba97337b89dfca (patch)
treed52e3a0f1f08f65ad283027e560e17ed0d720462 /src/lib/libcrypto/aes/aes_cbc.c
parent582bbd139cd2afd58d10dc051c5b0b989b441074 (diff)
downloadopenbsd-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/aes_cbc.c')
-rw-r--r--src/lib/libcrypto/aes/aes_cbc.c58
1 files changed, 40 insertions, 18 deletions
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}