xref: /netbsd-src/crypto/external/bsd/openssl/dist/crypto/rc2/rc2ofb64.c (revision 8fbed61efdd901c0e09614c9f45356aeeab23fe3)
15af53050Schristos /*
2*8fbed61eSchristos  * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3a89c9211Schristos  *
4*8fbed61eSchristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
55af53050Schristos  * this file except in compliance with the License.  You can obtain a copy
65af53050Schristos  * in the file LICENSE in the source distribution or at
75af53050Schristos  * https://www.openssl.org/source/license.html
8a89c9211Schristos  */
9a89c9211Schristos 
10*8fbed61eSchristos /*
11*8fbed61eSchristos  * RC2 low level APIs are deprecated for public use, but still ok for internal
12*8fbed61eSchristos  * use.
13*8fbed61eSchristos  */
14*8fbed61eSchristos #include "internal/deprecated.h"
15*8fbed61eSchristos 
16a89c9211Schristos #include <openssl/rc2.h>
1752629741Schristos #include "rc2_local.h"
18a89c9211Schristos 
199cef71b6Sspz /*
209cef71b6Sspz  * The input and output encrypted as though 64bit ofb mode is being used.
219cef71b6Sspz  * The extra state information to record how much of the 64bit block we have
229cef71b6Sspz  * used is contained in *num;
23a89c9211Schristos  */
RC2_ofb64_encrypt(const unsigned char * in,unsigned char * out,long length,RC2_KEY * schedule,unsigned char * ivec,int * num)24a89c9211Schristos void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
25a89c9211Schristos                        long length, RC2_KEY *schedule, unsigned char *ivec,
26a89c9211Schristos                        int *num)
27a89c9211Schristos {
2849d46fa3Schristos     register uint32_t v0, v1, t;
29a89c9211Schristos     register int n = *num;
30a89c9211Schristos     register long l = length;
31a89c9211Schristos     unsigned char d[8];
32a89c9211Schristos     register char *dp;
3349d46fa3Schristos     uint32_t ti[2];
34a89c9211Schristos     unsigned char *iv;
35a89c9211Schristos     int save = 0;
36a89c9211Schristos 
37a89c9211Schristos     iv = (unsigned char *)ivec;
38a89c9211Schristos     c2l(iv, v0);
39a89c9211Schristos     c2l(iv, v1);
40a89c9211Schristos     ti[0] = v0;
41a89c9211Schristos     ti[1] = v1;
42a89c9211Schristos     dp = (char *)d;
43a89c9211Schristos     l2c(v0, dp);
44a89c9211Schristos     l2c(v1, dp);
459cef71b6Sspz     while (l--) {
469cef71b6Sspz         if (n == 0) {
4749d46fa3Schristos             RC2_encrypt(ti, schedule);
48a89c9211Schristos             dp = (char *)d;
499cef71b6Sspz             t = ti[0];
509cef71b6Sspz             l2c(t, dp);
519cef71b6Sspz             t = ti[1];
529cef71b6Sspz             l2c(t, dp);
53a89c9211Schristos             save++;
54a89c9211Schristos         }
55a89c9211Schristos         *(out++) = *(in++) ^ d[n];
56a89c9211Schristos         n = (n + 1) & 0x07;
57a89c9211Schristos     }
589cef71b6Sspz     if (save) {
59a89c9211Schristos         v0 = ti[0];
60a89c9211Schristos         v1 = ti[1];
61a89c9211Schristos         iv = (unsigned char *)ivec;
62a89c9211Schristos         l2c(v0, iv);
63a89c9211Schristos         l2c(v1, iv);
64a89c9211Schristos     }
65a89c9211Schristos     t = v0 = v1 = ti[0] = ti[1] = 0;
66a89c9211Schristos     *num = n;
67a89c9211Schristos }
68