aboutsummaryrefslogtreecommitdiff
path: root/crypto/modes/cfb128.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/modes/cfb128.c')
-rw-r--r--crypto/modes/cfb128.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/crypto/modes/cfb128.c b/crypto/modes/cfb128.c
index 2d37bcb586fd..70345636dd3e 100644
--- a/crypto/modes/cfb128.c
+++ b/crypto/modes/cfb128.c
@@ -23,9 +23,9 @@ typedef size_t size_t_aX;
* used is contained in *num;
*/
void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
- size_t len, const void *key,
- unsigned char ivec[16], int *num,
- int enc, block128_f block)
+ size_t len, const void *key,
+ unsigned char ivec[16], int *num,
+ int enc, block128_f block)
{
unsigned int n;
size_t l = 0;
@@ -46,17 +46,15 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
--len;
n = (n + 1) % 16;
}
-# if defined(STRICT_ALIGNMENT)
- if (((size_t)in | (size_t)out | (size_t)ivec) %
- sizeof(size_t) != 0)
+#if defined(STRICT_ALIGNMENT)
+ if (((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0)
break;
-# endif
+#endif
while (len >= 16) {
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
for (; n < 16; n += sizeof(size_t)) {
- *(size_t_aX *)(out + n) =
- *(size_t_aX *)(ivec + n)
- ^= *(size_t_aX *)(in + n);
+ *(size_t_aX *)(out + n) = *(size_t_aX *)(ivec + n)
+ ^= *(size_t_aX *)(in + n);
}
len -= 16;
out += 16;
@@ -64,7 +62,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
n = 0;
}
if (len) {
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
while (len--) {
out[n] = ivec[n] ^= in[n];
++n;
@@ -78,7 +76,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
#endif
while (l < len) {
if (n == 0) {
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
}
out[l] = ivec[n] ^= in[l];
++l;
@@ -96,13 +94,12 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
--len;
n = (n + 1) % 16;
}
-# if defined(STRICT_ALIGNMENT)
- if (((size_t)in | (size_t)out | (size_t)ivec) %
- sizeof(size_t) != 0)
+#if defined(STRICT_ALIGNMENT)
+ if (((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0)
break;
-# endif
+#endif
while (len >= 16) {
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
for (; n < 16; n += sizeof(size_t)) {
size_t t = *(size_t_aX *)(in + n);
*(size_t_aX *)(out + n)
@@ -115,7 +112,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
n = 0;
}
if (len) {
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
while (len--) {
unsigned char c;
out[n] = ivec[n] ^ (c = in[n]);
@@ -132,7 +129,7 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
while (l < len) {
unsigned char c;
if (n == 0) {
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
}
out[l] = ivec[n] ^ (c = in[l]);
ivec[n] = c;
@@ -148,9 +145,9 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
* it corrupts any extra bits in the last byte of out
*/
static void cfbr_encrypt_block(const unsigned char *in, unsigned char *out,
- int nbits, const void *key,
- unsigned char ivec[16], int enc,
- block128_f block)
+ int nbits, const void *key,
+ unsigned char ivec[16], int enc,
+ block128_f block)
{
int n, rem, num;
unsigned char ovec[16 * 2 + 1]; /* +1 because we dereference (but don't
@@ -162,12 +159,12 @@ static void cfbr_encrypt_block(const unsigned char *in, unsigned char *out,
/* fill in the first half of the new IV with the current IV */
memcpy(ovec, ivec, 16);
/* construct the new IV */
- (*block) (ivec, ivec, key);
+ (*block)(ivec, ivec, key);
num = (nbits + 7) / 8;
- if (enc) /* encrypt the input */
+ if (enc) /* encrypt the input */
for (n = 0; n < num; ++n)
out[n] = (ovec[16 + n] = in[n] ^ ivec[n]);
- else /* decrypt the input */
+ else /* decrypt the input */
for (n = 0; n < num; ++n)
out[n] = (ovec[16 + n] = in[n]) ^ ivec[n];
/* shift ovec left... */
@@ -184,9 +181,9 @@ static void cfbr_encrypt_block(const unsigned char *in, unsigned char *out,
/* N.B. This expects the input to be packed, MS bit first */
void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
- size_t bits, const void *key,
- unsigned char ivec[16], int *num,
- int enc, block128_f block)
+ size_t bits, const void *key,
+ unsigned char ivec[16], int *num,
+ int enc, block128_f block)
{
size_t n;
unsigned char c[1], d[1];
@@ -194,15 +191,14 @@ void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
for (n = 0; n < bits; ++n) {
c[0] = (in[n / 8] & (1 << (7 - n % 8))) ? 0x80 : 0;
cfbr_encrypt_block(c, d, 1, key, ivec, enc, block);
- out[n / 8] = (out[n / 8] & ~(1 << (unsigned int)(7 - n % 8))) |
- ((d[0] & 0x80) >> (unsigned int)(n % 8));
+ out[n / 8] = (out[n / 8] & ~(1 << (unsigned int)(7 - n % 8))) | ((d[0] & 0x80) >> (unsigned int)(n % 8));
}
}
void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
- size_t length, const void *key,
- unsigned char ivec[16], int *num,
- int enc, block128_f block)
+ size_t length, const void *key,
+ unsigned char ivec[16], int *num,
+ int enc, block128_f block)
{
size_t n;