2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
11 #include <openssl/rc5.h>
14 void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out,
15 long length, RC5_32_KEY *ks, unsigned char *iv,
18 register unsigned long tin0, tin1;
19 register unsigned long tout0, tout1, xor0, xor1;
20 register long l = length;
27 for (l -= 8; l >= 0; l -= 8) {
34 RC5_32_encrypt(tin, ks);
41 c2ln(in, tin0, tin1, l + 8);
46 RC5_32_encrypt(tin, ks);
58 for (l -= 8; l >= 0; l -= 8) {
63 RC5_32_decrypt(tin, ks);
64 tout0 = tin[0] ^ xor0;
65 tout1 = tin[1] ^ xor1;
76 RC5_32_decrypt(tin, ks);
77 tout0 = tin[0] ^ xor0;
78 tout1 = tin[1] ^ xor1;
79 l2cn(tout0, tout1, out, l + 8);
86 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
90 void RC5_32_encrypt(unsigned long *d, RC5_32_KEY *key)
100 E_RC5_32(a, b, s, 6);
101 E_RC5_32(a, b, s, 8);
102 E_RC5_32(a, b, s, 10);
103 E_RC5_32(a, b, s, 12);
104 E_RC5_32(a, b, s, 14);
105 E_RC5_32(a, b, s, 16);
106 if (key->rounds == 12) {
107 E_RC5_32(a, b, s, 18);
108 E_RC5_32(a, b, s, 20);
109 E_RC5_32(a, b, s, 22);
110 E_RC5_32(a, b, s, 24);
111 } else if (key->rounds == 16) {
112 /* Do a full expansion to avoid a jump */
113 E_RC5_32(a, b, s, 18);
114 E_RC5_32(a, b, s, 20);
115 E_RC5_32(a, b, s, 22);
116 E_RC5_32(a, b, s, 24);
117 E_RC5_32(a, b, s, 26);
118 E_RC5_32(a, b, s, 28);
119 E_RC5_32(a, b, s, 30);
120 E_RC5_32(a, b, s, 32);
126 void RC5_32_decrypt(unsigned long *d, RC5_32_KEY *key)
134 if (key->rounds == 16) {
135 D_RC5_32(a, b, s, 32);
136 D_RC5_32(a, b, s, 30);
137 D_RC5_32(a, b, s, 28);
138 D_RC5_32(a, b, s, 26);
139 /* Do a full expansion to avoid a jump */
140 D_RC5_32(a, b, s, 24);
141 D_RC5_32(a, b, s, 22);
142 D_RC5_32(a, b, s, 20);
143 D_RC5_32(a, b, s, 18);
144 } else if (key->rounds == 12) {
145 D_RC5_32(a, b, s, 24);
146 D_RC5_32(a, b, s, 22);
147 D_RC5_32(a, b, s, 20);
148 D_RC5_32(a, b, s, 18);
150 D_RC5_32(a, b, s, 16);
151 D_RC5_32(a, b, s, 14);
152 D_RC5_32(a, b, s, 12);
153 D_RC5_32(a, b, s, 10);
154 D_RC5_32(a, b, s, 8);
155 D_RC5_32(a, b, s, 6);
156 D_RC5_32(a, b, s, 4);
157 D_RC5_32(a, b, s, 2);