2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
11 * RC5 low level APIs are deprecated for public use, but still ok for internal
14 #include "internal/deprecated.h"
17 #include <openssl/rc5.h>
18 #include "rc5_local.h"
20 void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out,
21 long length, RC5_32_KEY *ks, unsigned char *iv,
24 register unsigned long tin0, tin1;
25 register unsigned long tout0, tout1, xor0, xor1;
26 register long l = length;
33 for (l -= 8; l >= 0; l -= 8) {
40 RC5_32_encrypt(tin, ks);
47 c2ln(in, tin0, tin1, l + 8);
52 RC5_32_encrypt(tin, ks);
64 for (l -= 8; l >= 0; l -= 8) {
69 RC5_32_decrypt(tin, ks);
70 tout0 = tin[0] ^ xor0;
71 tout1 = tin[1] ^ xor1;
82 RC5_32_decrypt(tin, ks);
83 tout0 = tin[0] ^ xor0;
84 tout1 = tin[1] ^ xor1;
85 l2cn(tout0, tout1, out, l + 8);
92 tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
96 void RC5_32_encrypt(unsigned long *d, RC5_32_KEY *key)
104 E_RC5_32(a, b, s, 2);
105 E_RC5_32(a, b, s, 4);
106 E_RC5_32(a, b, s, 6);
107 E_RC5_32(a, b, s, 8);
108 E_RC5_32(a, b, s, 10);
109 E_RC5_32(a, b, s, 12);
110 E_RC5_32(a, b, s, 14);
111 E_RC5_32(a, b, s, 16);
112 if (key->rounds == 12) {
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 } else if (key->rounds == 16) {
118 /* Do a full expansion to avoid a jump */
119 E_RC5_32(a, b, s, 18);
120 E_RC5_32(a, b, s, 20);
121 E_RC5_32(a, b, s, 22);
122 E_RC5_32(a, b, s, 24);
123 E_RC5_32(a, b, s, 26);
124 E_RC5_32(a, b, s, 28);
125 E_RC5_32(a, b, s, 30);
126 E_RC5_32(a, b, s, 32);
132 void RC5_32_decrypt(unsigned long *d, RC5_32_KEY *key)
140 if (key->rounds == 16) {
141 D_RC5_32(a, b, s, 32);
142 D_RC5_32(a, b, s, 30);
143 D_RC5_32(a, b, s, 28);
144 D_RC5_32(a, b, s, 26);
145 /* Do a full expansion to avoid a jump */
146 D_RC5_32(a, b, s, 24);
147 D_RC5_32(a, b, s, 22);
148 D_RC5_32(a, b, s, 20);
149 D_RC5_32(a, b, s, 18);
150 } else if (key->rounds == 12) {
151 D_RC5_32(a, b, s, 24);
152 D_RC5_32(a, b, s, 22);
153 D_RC5_32(a, b, s, 20);
154 D_RC5_32(a, b, s, 18);
156 D_RC5_32(a, b, s, 16);
157 D_RC5_32(a, b, s, 14);
158 D_RC5_32(a, b, s, 12);
159 D_RC5_32(a, b, s, 10);
160 D_RC5_32(a, b, s, 8);
161 D_RC5_32(a, b, s, 6);
162 D_RC5_32(a, b, s, 4);
163 D_RC5_32(a, b, s, 2);