| 1 |
/* |
| 2 |
* Copyright 1995-2026 The OpenSSL Project Authors. All Rights Reserved. |
| 3 |
* |
| 4 |
* Licensed under the Apache License 2.0 (the "License"). You may not use |
| 5 |
* this file except in compliance with the License. You can obtain a copy |
| 6 |
* in the file LICENSE in the source distribution or at |
| 7 |
* https://www.openssl.org/source/license.html |
| 8 |
*/ |
| 9 |
|
| 10 |
/* |
| 11 |
* IDEA low level APIs are deprecated for public use, but still ok for internal |
| 12 |
* use where we're using them to implement the higher level EVP interface, as is |
| 13 |
* the case here. |
| 14 |
*/ |
| 15 |
#include "internal/deprecated.h" |
| 16 |
|
| 17 |
#include <openssl/idea.h> |
| 18 |
#include "idea_local.h" |
| 19 |
|
| 20 |
/* |
| 21 |
* The input and output encrypted as though 64bit cfb mode is being used. |
| 22 |
* The extra state information to record how much of the 64bit block we have |
| 23 |
* used is contained in *num; |
| 24 |
*/ |
| 25 |
|
| 26 |
void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out, |
| 27 |
long length, IDEA_KEY_SCHEDULE *schedule, |
| 28 |
unsigned char *ivec, int *num, int encrypt) |
| 29 |
{ |
| 30 |
register unsigned long v0, v1, t; |
| 31 |
register int n = *num; |
| 32 |
register long l = length; |
| 33 |
unsigned long ti[2]; |
| 34 |
unsigned char *iv, c, cc; |
| 35 |
|
| 36 |
if (n < 0) { |
| 37 |
*num = -1; |
| 38 |
return; |
| 39 |
} |
| 40 |
n = n & 0x07; |
| 41 |
|
| 42 |
iv = (unsigned char *)ivec; |
| 43 |
if (encrypt) { |
| 44 |
while (l--) { |
| 45 |
if (n == 0) { |
| 46 |
n2l(iv, v0); |
| 47 |
ti[0] = v0; |
| 48 |
n2l(iv, v1); |
| 49 |
ti[1] = v1; |
| 50 |
IDEA_encrypt((unsigned long *)ti, schedule); |
| 51 |
iv = (unsigned char *)ivec; |
| 52 |
t = ti[0]; |
| 53 |
l2n(t, iv); |
| 54 |
t = ti[1]; |
| 55 |
l2n(t, iv); |
| 56 |
iv = (unsigned char *)ivec; |
| 57 |
} |
| 58 |
c = *(in++) ^ iv[n]; |
| 59 |
*(out++) = c; |
| 60 |
iv[n] = c; |
| 61 |
n = (n + 1) & 0x07; |
| 62 |
} |
| 63 |
} else { |
| 64 |
while (l--) { |
| 65 |
if (n == 0) { |
| 66 |
n2l(iv, v0); |
| 67 |
ti[0] = v0; |
| 68 |
n2l(iv, v1); |
| 69 |
ti[1] = v1; |
| 70 |
IDEA_encrypt((unsigned long *)ti, schedule); |
| 71 |
iv = (unsigned char *)ivec; |
| 72 |
t = ti[0]; |
| 73 |
l2n(t, iv); |
| 74 |
t = ti[1]; |
| 75 |
l2n(t, iv); |
| 76 |
iv = (unsigned char *)ivec; |
| 77 |
} |
| 78 |
cc = *(in++); |
| 79 |
c = iv[n]; |
| 80 |
iv[n] = cc; |
| 81 |
*(out++) = c ^ cc; |
| 82 |
n = (n + 1) & 0x07; |
| 83 |
} |
| 84 |
} |
| 85 |
v0 = v1 = ti[0] = ti[1] = t = c = cc = 0; |
| 86 |
*num = n; |
| 87 |
} |