Blame crypto/rc2/rc2ofb64.c
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <openssl/rc2.h>
|
|
Packit Service |
084de1 |
#include "rc2_local.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* The input and output encrypted as though 64bit ofb mode is being used.
|
|
Packit Service |
084de1 |
* The extra state information to record how much of the 64bit block we have
|
|
Packit Service |
084de1 |
* used is contained in *num;
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
|
Packit Service |
084de1 |
long length, RC2_KEY *schedule, unsigned char *ivec,
|
|
Packit Service |
084de1 |
int *num)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
register unsigned long v0, v1, t;
|
|
Packit Service |
084de1 |
register int n = *num;
|
|
Packit Service |
084de1 |
register long l = length;
|
|
Packit Service |
084de1 |
unsigned char d[8];
|
|
Packit Service |
084de1 |
register char *dp;
|
|
Packit Service |
084de1 |
unsigned long ti[2];
|
|
Packit Service |
084de1 |
unsigned char *iv;
|
|
Packit Service |
084de1 |
int save = 0;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
iv = (unsigned char *)ivec;
|
|
Packit Service |
084de1 |
c2l(iv, v0);
|
|
Packit Service |
084de1 |
c2l(iv, v1);
|
|
Packit Service |
084de1 |
ti[0] = v0;
|
|
Packit Service |
084de1 |
ti[1] = v1;
|
|
Packit Service |
084de1 |
dp = (char *)d;
|
|
Packit Service |
084de1 |
l2c(v0, dp);
|
|
Packit Service |
084de1 |
l2c(v1, dp);
|
|
Packit Service |
084de1 |
while (l--) {
|
|
Packit Service |
084de1 |
if (n == 0) {
|
|
Packit Service |
084de1 |
RC2_encrypt((unsigned long *)ti, schedule);
|
|
Packit Service |
084de1 |
dp = (char *)d;
|
|
Packit Service |
084de1 |
t = ti[0];
|
|
Packit Service |
084de1 |
l2c(t, dp);
|
|
Packit Service |
084de1 |
t = ti[1];
|
|
Packit Service |
084de1 |
l2c(t, dp);
|
|
Packit Service |
084de1 |
save++;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
*(out++) = *(in++) ^ d[n];
|
|
Packit Service |
084de1 |
n = (n + 1) & 0x07;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
if (save) {
|
|
Packit Service |
084de1 |
v0 = ti[0];
|
|
Packit Service |
084de1 |
v1 = ti[1];
|
|
Packit Service |
084de1 |
iv = (unsigned char *)ivec;
|
|
Packit Service |
084de1 |
l2c(v0, iv);
|
|
Packit Service |
084de1 |
l2c(v1, iv);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
t = v0 = v1 = ti[0] = ti[1] = 0;
|
|
Packit Service |
084de1 |
*num = n;
|
|
Packit Service |
084de1 |
}
|