1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Upgrade openssl from 1.1.0e to 1.1.1b, with source code. 4.0.78

This commit is contained in:
winlin 2021-03-01 20:47:57 +08:00
parent 8f1c992379
commit 96dbd7bced
1476 changed files with 616554 additions and 4 deletions

View file

@ -0,0 +1,122 @@
#! /usr/bin/env perl
# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
push(@INC,"${dir}","${dir}../../perlasm");
require "x86asm.pl";
require "cbc.pl";
$output = pop;
open STDOUT,">$output";
&asm_init($ARGV[0]);
$RC5_MAX_ROUNDS=16;
$RC5_32_OFF=($RC5_MAX_ROUNDS+2)*4;
$A="edi";
$B="esi";
$S="ebp";
$tmp1="eax";
$r="ebx";
$tmpc="ecx";
$tmp4="edx";
&RC5_32_encrypt("RC5_32_encrypt",1);
&RC5_32_encrypt("RC5_32_decrypt",0);
&cbc("RC5_32_cbc_encrypt","RC5_32_encrypt","RC5_32_decrypt",0,4,5,3,-1,-1);
&asm_finish();
close STDOUT;
sub RC5_32_encrypt
{
local($name,$enc)=@_;
&function_begin_B($name,"");
&comment("");
&push("ebp");
&push("esi");
&push("edi");
&mov($tmp4,&wparam(0));
&mov($S,&wparam(1));
&comment("Load the 2 words");
&mov($A,&DWP(0,$tmp4,"",0));
&mov($B,&DWP(4,$tmp4,"",0));
&push($r);
&mov($r, &DWP(0,$S,"",0));
# encrypting part
if ($enc)
{
&add($A, &DWP(4+0,$S,"",0));
&add($B, &DWP(4+4,$S,"",0));
for ($i=0; $i<$RC5_MAX_ROUNDS; $i++)
{
&xor($A, $B);
&mov($tmp1, &DWP(12+$i*8,$S,"",0));
&mov($tmpc, $B);
&rotl($A, &LB("ecx"));
&add($A, $tmp1);
&xor($B, $A);
&mov($tmp1, &DWP(16+$i*8,$S,"",0));
&mov($tmpc, $A);
&rotl($B, &LB("ecx"));
&add($B, $tmp1);
if (($i == 7) || ($i == 11))
{
&cmp($r, $i+1);
&je(&label("rc5_exit"));
}
}
}
else
{
&cmp($r, 12);
&je(&label("rc5_dec_12"));
&cmp($r, 8);
&je(&label("rc5_dec_8"));
for ($i=$RC5_MAX_ROUNDS; $i > 0; $i--)
{
&set_label("rc5_dec_$i") if ($i == 12) || ($i == 8);
&mov($tmp1, &DWP($i*8+8,$S,"",0));
&sub($B, $tmp1);
&mov($tmpc, $A);
&rotr($B, &LB("ecx"));
&xor($B, $A);
&mov($tmp1, &DWP($i*8+4,$S,"",0));
&sub($A, $tmp1);
&mov($tmpc, $B);
&rotr($A, &LB("ecx"));
&xor($A, $B);
}
&sub($B, &DWP(4+4,$S,"",0));
&sub($A, &DWP(4+0,$S,"",0));
}
&set_label("rc5_exit");
&mov(&DWP(0,$tmp4,"",0),$A);
&mov(&DWP(4,$tmp4,"",0),$B);
&pop("ebx");
&pop("edi");
&pop("esi");
&pop("ebp");
&ret();
&function_end_B($name);
}

View file

@ -0,0 +1,7 @@
LIBS=../../libcrypto
SOURCE[../../libcrypto]=\
rc5_skey.c rc5_ecb.c {- $target{rc5_asm_src} -} rc5cfb64.c rc5ofb64.c
GENERATE[rc5-586.s]=asm/rc5-586.pl \
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS)
DEPEND[rc5-586.s]=../perlasm/x86asm.pl ../perlasm/cbc.pl

View file

@ -0,0 +1,32 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/rc5.h>
#include "rc5_locl.h"
#include <openssl/opensslv.h>
void RC5_32_ecb_encrypt(const unsigned char *in, unsigned char *out,
RC5_32_KEY *ks, int encrypt)
{
unsigned long l, d[2];
c2l(in, l);
d[0] = l;
c2l(in, l);
d[1] = l;
if (encrypt)
RC5_32_encrypt(d, ks);
else
RC5_32_decrypt(d, ks);
l = d[0];
l2c(l, out);
l = d[1];
l2c(l, out);
l = d[0] = d[1] = 0;
}

View file

@ -0,0 +1,160 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <openssl/rc5.h>
#include "rc5_locl.h"
void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out,
long length, RC5_32_KEY *ks, unsigned char *iv,
int encrypt)
{
register unsigned long tin0, tin1;
register unsigned long tout0, tout1, xor0, xor1;
register long l = length;
unsigned long tin[2];
if (encrypt) {
c2l(iv, tout0);
c2l(iv, tout1);
iv -= 8;
for (l -= 8; l >= 0; l -= 8) {
c2l(in, tin0);
c2l(in, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
RC5_32_encrypt(tin, ks);
tout0 = tin[0];
l2c(tout0, out);
tout1 = tin[1];
l2c(tout1, out);
}
if (l != -8) {
c2ln(in, tin0, tin1, l + 8);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
RC5_32_encrypt(tin, ks);
tout0 = tin[0];
l2c(tout0, out);
tout1 = tin[1];
l2c(tout1, out);
}
l2c(tout0, iv);
l2c(tout1, iv);
} else {
c2l(iv, xor0);
c2l(iv, xor1);
iv -= 8;
for (l -= 8; l >= 0; l -= 8) {
c2l(in, tin0);
tin[0] = tin0;
c2l(in, tin1);
tin[1] = tin1;
RC5_32_decrypt(tin, ks);
tout0 = tin[0] ^ xor0;
tout1 = tin[1] ^ xor1;
l2c(tout0, out);
l2c(tout1, out);
xor0 = tin0;
xor1 = tin1;
}
if (l != -8) {
c2l(in, tin0);
tin[0] = tin0;
c2l(in, tin1);
tin[1] = tin1;
RC5_32_decrypt(tin, ks);
tout0 = tin[0] ^ xor0;
tout1 = tin[1] ^ xor1;
l2cn(tout0, tout1, out, l + 8);
xor0 = tin0;
xor1 = tin1;
}
l2c(xor0, iv);
l2c(xor1, iv);
}
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
tin[0] = tin[1] = 0;
}
void RC5_32_encrypt(unsigned long *d, RC5_32_KEY *key)
{
RC5_32_INT a, b, *s;
s = key->data;
a = d[0] + s[0];
b = d[1] + s[1];
E_RC5_32(a, b, s, 2);
E_RC5_32(a, b, s, 4);
E_RC5_32(a, b, s, 6);
E_RC5_32(a, b, s, 8);
E_RC5_32(a, b, s, 10);
E_RC5_32(a, b, s, 12);
E_RC5_32(a, b, s, 14);
E_RC5_32(a, b, s, 16);
if (key->rounds == 12) {
E_RC5_32(a, b, s, 18);
E_RC5_32(a, b, s, 20);
E_RC5_32(a, b, s, 22);
E_RC5_32(a, b, s, 24);
} else if (key->rounds == 16) {
/* Do a full expansion to avoid a jump */
E_RC5_32(a, b, s, 18);
E_RC5_32(a, b, s, 20);
E_RC5_32(a, b, s, 22);
E_RC5_32(a, b, s, 24);
E_RC5_32(a, b, s, 26);
E_RC5_32(a, b, s, 28);
E_RC5_32(a, b, s, 30);
E_RC5_32(a, b, s, 32);
}
d[0] = a;
d[1] = b;
}
void RC5_32_decrypt(unsigned long *d, RC5_32_KEY *key)
{
RC5_32_INT a, b, *s;
s = key->data;
a = d[0];
b = d[1];
if (key->rounds == 16) {
D_RC5_32(a, b, s, 32);
D_RC5_32(a, b, s, 30);
D_RC5_32(a, b, s, 28);
D_RC5_32(a, b, s, 26);
/* Do a full expansion to avoid a jump */
D_RC5_32(a, b, s, 24);
D_RC5_32(a, b, s, 22);
D_RC5_32(a, b, s, 20);
D_RC5_32(a, b, s, 18);
} else if (key->rounds == 12) {
D_RC5_32(a, b, s, 24);
D_RC5_32(a, b, s, 22);
D_RC5_32(a, b, s, 20);
D_RC5_32(a, b, s, 18);
}
D_RC5_32(a, b, s, 16);
D_RC5_32(a, b, s, 14);
D_RC5_32(a, b, s, 12);
D_RC5_32(a, b, s, 10);
D_RC5_32(a, b, s, 8);
D_RC5_32(a, b, s, 6);
D_RC5_32(a, b, s, 4);
D_RC5_32(a, b, s, 2);
d[0] = a - s[0];
d[1] = b - s[1];
}

View file

@ -0,0 +1,186 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdlib.h>
#undef c2l
#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
l|=((unsigned long)(*((c)++)))<< 8L, \
l|=((unsigned long)(*((c)++)))<<16L, \
l|=((unsigned long)(*((c)++)))<<24L)
/* NOTE - c is not incremented as per c2l */
#undef c2ln
#define c2ln(c,l1,l2,n) { \
c+=n; \
l1=l2=0; \
switch (n) { \
case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
/* fall thru */ \
case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
/* fall thru */ \
case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
/* fall thru */ \
case 5: l2|=((unsigned long)(*(--(c)))); \
/* fall thru */ \
case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
/* fall thru */ \
case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
/* fall thru */ \
case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
/* fall thru */ \
case 1: l1|=((unsigned long)(*(--(c)))); \
} \
}
#undef l2c
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
/* NOTE - c is not incremented as per l2c */
#undef l2cn
#define l2cn(l1,l2,c,n) { \
c+=n; \
switch (n) { \
case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
/* fall thru */ \
case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
/* fall thru */ \
case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
/* fall thru */ \
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
/* fall thru */ \
case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
/* fall thru */ \
case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
/* fall thru */ \
case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
/* fall thru */ \
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
} \
}
/* NOTE - c is not incremented as per n2l */
#define n2ln(c,l1,l2,n) { \
c+=n; \
l1=l2=0; \
switch (n) { \
case 8: l2 =((unsigned long)(*(--(c)))) ; \
/* fall thru */ \
case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
/* fall thru */ \
case 6: l2|=((unsigned long)(*(--(c))))<<16; \
/* fall thru */ \
case 5: l2|=((unsigned long)(*(--(c))))<<24; \
/* fall thru */ \
case 4: l1 =((unsigned long)(*(--(c)))) ; \
/* fall thru */ \
case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
/* fall thru */ \
case 2: l1|=((unsigned long)(*(--(c))))<<16; \
/* fall thru */ \
case 1: l1|=((unsigned long)(*(--(c))))<<24; \
} \
}
/* NOTE - c is not incremented as per l2n */
#define l2nn(l1,l2,c,n) { \
c+=n; \
switch (n) { \
case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
/* fall thru */ \
case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
/* fall thru */ \
case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
/* fall thru */ \
case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
/* fall thru */ \
case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
/* fall thru */ \
case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
/* fall thru */ \
case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
/* fall thru */ \
case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
} \
}
#undef n2l
#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
l|=((unsigned long)(*((c)++)))<<16L, \
l|=((unsigned long)(*((c)++)))<< 8L, \
l|=((unsigned long)(*((c)++))))
#undef l2n
#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff))
#if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER))
# define ROTATE_l32(a,n) _lrotl(a,n)
# define ROTATE_r32(a,n) _lrotr(a,n)
#elif defined(__ICC)
# define ROTATE_l32(a,n) _rotl(a,n)
# define ROTATE_r32(a,n) _rotr(a,n)
#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
# define ROTATE_l32(a,n) ({ register unsigned int ret; \
asm ("roll %%cl,%0" \
: "=r"(ret) \
: "c"(n),"0"((unsigned int)(a)) \
: "cc"); \
ret; \
})
# define ROTATE_r32(a,n) ({ register unsigned int ret; \
asm ("rorl %%cl,%0" \
: "=r"(ret) \
: "c"(n),"0"((unsigned int)(a)) \
: "cc"); \
ret; \
})
# endif
#endif
#ifndef ROTATE_l32
# define ROTATE_l32(a,n) (((a)<<(n&0x1f))|(((a)&0xffffffff)>>((32-n)&0x1f)))
#endif
#ifndef ROTATE_r32
# define ROTATE_r32(a,n) (((a)<<((32-n)&0x1f))|(((a)&0xffffffff)>>(n&0x1f)))
#endif
#define RC5_32_MASK 0xffffffffL
#define RC5_16_P 0xB7E1
#define RC5_16_Q 0x9E37
#define RC5_32_P 0xB7E15163L
#define RC5_32_Q 0x9E3779B9L
#define RC5_64_P 0xB7E151628AED2A6BLL
#define RC5_64_Q 0x9E3779B97F4A7C15LL
#define E_RC5_32(a,b,s,n) \
a^=b; \
a=ROTATE_l32(a,b); \
a+=s[n]; \
a&=RC5_32_MASK; \
b^=a; \
b=ROTATE_l32(b,a); \
b+=s[n+1]; \
b&=RC5_32_MASK;
#define D_RC5_32(a,b,s,n) \
b-=s[n+1]; \
b&=RC5_32_MASK; \
b=ROTATE_r32(b,a); \
b^=a; \
a-=s[n]; \
a&=RC5_32_MASK; \
a=ROTATE_r32(a,b); \
a^=b;

View file

@ -0,0 +1,61 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/rc5.h>
#include "rc5_locl.h"
void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
int rounds)
{
RC5_32_INT L[64], l, ll, A, B, *S, k;
int i, j, m, c, t, ii, jj;
if ((rounds != RC5_16_ROUNDS) &&
(rounds != RC5_12_ROUNDS) && (rounds != RC5_8_ROUNDS))
rounds = RC5_16_ROUNDS;
key->rounds = rounds;
S = &(key->data[0]);
j = 0;
for (i = 0; i <= (len - 8); i += 8) {
c2l(data, l);
L[j++] = l;
c2l(data, l);
L[j++] = l;
}
ii = len - i;
if (ii) {
k = len & 0x07;
c2ln(data, l, ll, k);
L[j + 0] = l;
L[j + 1] = ll;
}
c = (len + 3) / 4;
t = (rounds + 1) * 2;
S[0] = RC5_32_P;
for (i = 1; i < t; i++)
S[i] = (S[i - 1] + RC5_32_Q) & RC5_32_MASK;
j = (t > c) ? t : c;
j *= 3;
ii = jj = 0;
A = B = 0;
for (i = 0; i < j; i++) {
k = (S[ii] + A + B) & RC5_32_MASK;
A = S[ii] = ROTATE_l32(k, 3);
m = (int)(A + B);
k = (L[jj] + A + B) & RC5_32_MASK;
B = L[jj] = ROTATE_l32(k, m);
if (++ii >= t)
ii = 0;
if (++jj >= c)
jj = 0;
}
}

View file

@ -0,0 +1,74 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/rc5.h>
#include "rc5_locl.h"
/*
* The input and output encrypted as though 64bit cfb mode is being used.
* The extra state information to record how much of the 64bit block we have
* used is contained in *num;
*/
void RC5_32_cfb64_encrypt(const unsigned char *in, unsigned char *out,
long length, RC5_32_KEY *schedule,
unsigned char *ivec, int *num, int encrypt)
{
register unsigned long v0, v1, t;
register int n = *num;
register long l = length;
unsigned long ti[2];
unsigned char *iv, c, cc;
iv = (unsigned char *)ivec;
if (encrypt) {
while (l--) {
if (n == 0) {
c2l(iv, v0);
ti[0] = v0;
c2l(iv, v1);
ti[1] = v1;
RC5_32_encrypt((unsigned long *)ti, schedule);
iv = (unsigned char *)ivec;
t = ti[0];
l2c(t, iv);
t = ti[1];
l2c(t, iv);
iv = (unsigned char *)ivec;
}
c = *(in++) ^ iv[n];
*(out++) = c;
iv[n] = c;
n = (n + 1) & 0x07;
}
} else {
while (l--) {
if (n == 0) {
c2l(iv, v0);
ti[0] = v0;
c2l(iv, v1);
ti[1] = v1;
RC5_32_encrypt((unsigned long *)ti, schedule);
iv = (unsigned char *)ivec;
t = ti[0];
l2c(t, iv);
t = ti[1];
l2c(t, iv);
iv = (unsigned char *)ivec;
}
cc = *(in++);
c = iv[n];
iv[n] = cc;
*(out++) = c ^ cc;
n = (n + 1) & 0x07;
}
}
v0 = v1 = ti[0] = ti[1] = t = c = cc = 0;
*num = n;
}

View file

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