]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/idea/i_cfb64.c
PROV: add RSA signature implementation
[thirdparty/openssl.git] / crypto / idea / i_cfb64.c
CommitLineData
2039c421
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
0f113f3e 3 *
aa2d9a76 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
2039c421
RS
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
d02b48c6
RE
8 */
9
da2d32f6
P
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
ec577822 17#include <openssl/idea.h>
706457b7 18#include "idea_local.h"
d02b48c6 19
0f113f3e
MC
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;
d02b48c6
RE
24 */
25
9021a5df 26void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out,
0f113f3e
MC
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;
d02b48c6 35
0f113f3e
MC
36 iv = (unsigned char *)ivec;
37 if (encrypt) {
38 while (l--) {
39 if (n == 0) {
40 n2l(iv, v0);
41 ti[0] = v0;
42 n2l(iv, v1);
43 ti[1] = v1;
9021a5df 44 IDEA_encrypt((unsigned long *)ti, schedule);
0f113f3e
MC
45 iv = (unsigned char *)ivec;
46 t = ti[0];
47 l2n(t, iv);
48 t = ti[1];
49 l2n(t, iv);
50 iv = (unsigned char *)ivec;
51 }
52 c = *(in++) ^ iv[n];
53 *(out++) = c;
54 iv[n] = c;
55 n = (n + 1) & 0x07;
56 }
57 } else {
58 while (l--) {
59 if (n == 0) {
60 n2l(iv, v0);
61 ti[0] = v0;
62 n2l(iv, v1);
63 ti[1] = v1;
9021a5df 64 IDEA_encrypt((unsigned long *)ti, schedule);
0f113f3e
MC
65 iv = (unsigned char *)ivec;
66 t = ti[0];
67 l2n(t, iv);
68 t = ti[1];
69 l2n(t, iv);
70 iv = (unsigned char *)ivec;
71 }
72 cc = *(in++);
73 c = iv[n];
74 iv[n] = cc;
75 *(out++) = c ^ cc;
76 n = (n + 1) & 0x07;
77 }
78 }
79 v0 = v1 = ti[0] = ti[1] = t = c = cc = 0;
80 *num = n;
81}