summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/aes/aes_ctr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/aes/aes_ctr.c')
-rw-r--r--src/lib/libcrypto/aes/aes_ctr.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/lib/libcrypto/aes/aes_ctr.c b/src/lib/libcrypto/aes/aes_ctr.c
index f36982be1e..79e1c18f19 100644
--- a/src/lib/libcrypto/aes/aes_ctr.c
+++ b/src/lib/libcrypto/aes/aes_ctr.c
@@ -59,7 +59,7 @@
59#include <openssl/aes.h> 59#include <openssl/aes.h>
60#include "aes_locl.h" 60#include "aes_locl.h"
61 61
62/* NOTE: the IV/counter CTR mode is big-endian. The rest of the AES code 62/* NOTE: CTR mode is big-endian. The rest of the AES code
63 * is endian-neutral. */ 63 * is endian-neutral. */
64 64
65/* increment counter (128-bit int) by 1 */ 65/* increment counter (128-bit int) by 1 */
@@ -67,36 +67,61 @@ static void AES_ctr128_inc(unsigned char *counter) {
67 unsigned long c; 67 unsigned long c;
68 68
69 /* Grab bottom dword of counter and increment */ 69 /* Grab bottom dword of counter and increment */
70#ifdef L_ENDIAN
71 c = GETU32(counter + 0);
72 c++;
73 PUTU32(counter + 0, c);
74#else
70 c = GETU32(counter + 12); 75 c = GETU32(counter + 12);
71 c++; c &= 0xFFFFFFFF; 76 c++;
72 PUTU32(counter + 12, c); 77 PUTU32(counter + 12, c);
78#endif
73 79
74 /* if no overflow, we're done */ 80 /* if no overflow, we're done */
75 if (c) 81 if (c)
76 return; 82 return;
77 83
78 /* Grab 1st dword of counter and increment */ 84 /* Grab 1st dword of counter and increment */
85#ifdef L_ENDIAN
86 c = GETU32(counter + 4);
87 c++;
88 PUTU32(counter + 4, c);
89#else
79 c = GETU32(counter + 8); 90 c = GETU32(counter + 8);
80 c++; c &= 0xFFFFFFFF; 91 c++;
81 PUTU32(counter + 8, c); 92 PUTU32(counter + 8, c);
93#endif
82 94
83 /* if no overflow, we're done */ 95 /* if no overflow, we're done */
84 if (c) 96 if (c)
85 return; 97 return;
86 98
87 /* Grab 2nd dword of counter and increment */ 99 /* Grab 2nd dword of counter and increment */
100#ifdef L_ENDIAN
101 c = GETU32(counter + 8);
102 c++;
103 PUTU32(counter + 8, c);
104#else
88 c = GETU32(counter + 4); 105 c = GETU32(counter + 4);
89 c++; c &= 0xFFFFFFFF; 106 c++;
90 PUTU32(counter + 4, c); 107 PUTU32(counter + 4, c);
108#endif
91 109
92 /* if no overflow, we're done */ 110 /* if no overflow, we're done */
93 if (c) 111 if (c)
94 return; 112 return;
95 113
96 /* Grab top dword of counter and increment */ 114 /* Grab top dword of counter and increment */
115#ifdef L_ENDIAN
116 c = GETU32(counter + 12);
117 c++;
118 PUTU32(counter + 12, c);
119#else
97 c = GETU32(counter + 0); 120 c = GETU32(counter + 0);
98 c++; c &= 0xFFFFFFFF; 121 c++;
99 PUTU32(counter + 0, c); 122 PUTU32(counter + 0, c);
123#endif
124
100} 125}
101 126
102/* The input encrypted as though 128bit counter mode is being 127/* The input encrypted as though 128bit counter mode is being