diff options
Diffstat (limited to 'src/lib/libcrypto/aes/aes_ctr.c')
| -rw-r--r-- | src/lib/libcrypto/aes/aes_ctr.c | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/src/lib/libcrypto/aes/aes_ctr.c b/src/lib/libcrypto/aes/aes_ctr.c index 79e1c18f19..f36982be1e 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: CTR mode is big-endian. The rest of the AES code | 62 | /* NOTE: the IV/counter 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,61 +67,36 @@ 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 | ||
| 75 | c = GETU32(counter + 12); | 70 | c = GETU32(counter + 12); |
| 76 | c++; | 71 | c++; c &= 0xFFFFFFFF; |
| 77 | PUTU32(counter + 12, c); | 72 | PUTU32(counter + 12, c); |
| 78 | #endif | ||
| 79 | 73 | ||
| 80 | /* if no overflow, we're done */ | 74 | /* if no overflow, we're done */ |
| 81 | if (c) | 75 | if (c) |
| 82 | return; | 76 | return; |
| 83 | 77 | ||
| 84 | /* Grab 1st dword of counter and increment */ | 78 | /* 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 | ||
| 90 | c = GETU32(counter + 8); | 79 | c = GETU32(counter + 8); |
| 91 | c++; | 80 | c++; c &= 0xFFFFFFFF; |
| 92 | PUTU32(counter + 8, c); | 81 | PUTU32(counter + 8, c); |
| 93 | #endif | ||
| 94 | 82 | ||
| 95 | /* if no overflow, we're done */ | 83 | /* if no overflow, we're done */ |
| 96 | if (c) | 84 | if (c) |
| 97 | return; | 85 | return; |
| 98 | 86 | ||
| 99 | /* Grab 2nd dword of counter and increment */ | 87 | /* 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 | ||
| 105 | c = GETU32(counter + 4); | 88 | c = GETU32(counter + 4); |
| 106 | c++; | 89 | c++; c &= 0xFFFFFFFF; |
| 107 | PUTU32(counter + 4, c); | 90 | PUTU32(counter + 4, c); |
| 108 | #endif | ||
| 109 | 91 | ||
| 110 | /* if no overflow, we're done */ | 92 | /* if no overflow, we're done */ |
| 111 | if (c) | 93 | if (c) |
| 112 | return; | 94 | return; |
| 113 | 95 | ||
| 114 | /* Grab top dword of counter and increment */ | 96 | /* 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 | ||
| 120 | c = GETU32(counter + 0); | 97 | c = GETU32(counter + 0); |
| 121 | c++; | 98 | c++; c &= 0xFFFFFFFF; |
| 122 | PUTU32(counter + 0, c); | 99 | PUTU32(counter + 0, c); |
| 123 | #endif | ||
| 124 | |||
| 125 | } | 100 | } |
| 126 | 101 | ||
| 127 | /* The input encrypted as though 128bit counter mode is being | 102 | /* The input encrypted as though 128bit counter mode is being |
