提交 f768be81 编写于 作者: A Andy Polyakov

size_t-fy AES, Camellia and RC4.

上级 91173829
......@@ -58,6 +58,8 @@
#error AES is disabled.
#endif
#include <stddef.h>
#define AES_ENCRYPT 1
#define AES_DECRYPT 0
......@@ -96,35 +98,35 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
const AES_KEY *key, const int enc);
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, const int enc);
void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num, const int enc);
void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num, const int enc);
void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num, const int enc);
void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
const int nbits,const AES_KEY *key,
unsigned char *ivec,const int enc);
void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num);
void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char ivec[AES_BLOCK_SIZE],
unsigned char ecount_buf[AES_BLOCK_SIZE],
unsigned int *num);
/* NB: the IV is _two_ blocks long */
void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, const int enc);
/* NB: the IV is _four_ blocks long */
void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
const AES_KEY *key2, const unsigned char *ivec,
const int enc);
......
......@@ -60,11 +60,10 @@
#include "aes_locl.h"
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t len, const AES_KEY *key,
unsigned char *ivec, const int enc) {
unsigned long n;
unsigned long len = length;
size_t n;
unsigned char tmp[AES_BLOCK_SIZE];
const unsigned char *iv = ivec;
......
......@@ -73,11 +73,11 @@
*/
void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num, const int enc) {
unsigned int n;
unsigned long l = 0;
size_t l = 0;
assert(in && out && key && ivec && num);
......@@ -219,10 +219,10 @@ void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
/* N.B. This expects the input to be packed, MS bit first */
void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num, const int enc)
{
unsigned int n;
size_t n;
unsigned char c[1],d[1];
assert(in && out && key && ivec && num);
......@@ -238,10 +238,10 @@ void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
}
void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num, const int enc)
{
unsigned int n;
size_t n;
assert(in && out && key && ivec && num);
assert(*num == 0);
......
......@@ -113,20 +113,19 @@ static void AES_ctr128_inc(unsigned char *counter) {
* into the rest of the IV when incremented.
*/
void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char ivec[AES_BLOCK_SIZE],
unsigned char ecount_buf[AES_BLOCK_SIZE],
unsigned int *num) {
unsigned int n;
unsigned long l=length;
assert(in && out && key && counter && num);
assert(*num < AES_BLOCK_SIZE);
n = *num;
while (l--) {
while (length--) {
if (n == 0) {
AES_encrypt(ivec, ecount_buf, key);
AES_ctr128_inc(ivec);
......
......@@ -77,11 +77,11 @@ typedef struct {
/* N.B. The IV for this mode is _twice_ the block size */
void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, const int enc)
{
unsigned long n;
unsigned long len;
size_t n;
size_t len = length;
OPENSSL_assert(in && out && key && ivec);
OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
......@@ -211,12 +211,12 @@ void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
/* N.B. The IV for this mode is _four times_ the block size */
void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
const AES_KEY *key2, const unsigned char *ivec,
const int enc)
{
unsigned long n;
unsigned long len = length;
size_t n;
size_t len = length;
unsigned char tmp[AES_BLOCK_SIZE];
unsigned char tmp2[AES_BLOCK_SIZE];
unsigned char tmp3[AES_BLOCK_SIZE];
......
......@@ -71,11 +71,11 @@
* 128bit block we have used is contained in *num;
*/
void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
unsigned long length, const AES_KEY *key,
size_t length, const AES_KEY *key,
unsigned char *ivec, int *num) {
unsigned int n;
unsigned long l=0;
size_t l=0;
assert(in && out && key && ivec && num);
......
......@@ -58,6 +58,8 @@
#error CAMELLIA is disabled.
#endif
#include <stddef.h>
#define CAMELLIA_ENCRYPT 1
#define CAMELLIA_DECRYPT 0
......@@ -97,25 +99,25 @@ void Camellia_decrypt(const unsigned char *in, unsigned char *out,
void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out,
const CAMELLIA_KEY *key, const int enc);
void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, const int enc);
void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num, const int enc);
void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num, const int enc);
void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num, const int enc);
void Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
const int nbits,const CAMELLIA_KEY *key,
unsigned char *ivec,const int enc);
void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num);
void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char ivec[CAMELLIA_BLOCK_SIZE],
unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE],
unsigned int *num);
......
......@@ -60,12 +60,11 @@
#include <openssl/camellia.h>
#include "cmll_locl.h"
void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t len, const CAMELLIA_KEY *key,
unsigned char *ivec, const int enc)
{
unsigned long n;
unsigned long len = length;
size_t n;
unsigned char tmp[CAMELLIA_BLOCK_SIZE];
const unsigned char *iv = ivec;
......
......@@ -124,12 +124,11 @@
*/
void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num, const int enc)
{
unsigned int n;
unsigned long l = length;
unsigned char c;
assert(in && out && key && ivec && num);
......@@ -138,7 +137,7 @@ void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
if (enc)
{
while (l--)
while (length--)
{
if (n == 0)
{
......@@ -150,7 +149,7 @@ void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out,
}
else
{
while (l--)
while (length--)
{
if (n == 0)
{
......@@ -202,10 +201,10 @@ void Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
/* N.B. This expects the input to be packed, MS bit first */
void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num, const int enc)
{
unsigned int n;
size_t n;
unsigned char c[1],d[1];
assert(in && out && key && ivec && num);
......@@ -221,10 +220,10 @@ void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out,
}
void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num, const int enc)
{
unsigned int n;
size_t n;
assert(in && out && key && ivec && num);
assert(*num == 0);
......
......@@ -113,21 +113,20 @@ static void Camellia_ctr128_inc(unsigned char *counter)
* into the rest of the IV when incremented.
*/
void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char ivec[CAMELLIA_BLOCK_SIZE],
unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE],
unsigned int *num)
{
unsigned int n;
unsigned long l=length;
assert(in && out && key && counter && num);
assert(*num < CAMELLIA_BLOCK_SIZE);
n = *num;
while (l--)
while (length--)
{
if (n == 0)
{
......
......@@ -119,17 +119,16 @@
* 128bit block we have used is contained in *num;
*/
void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const CAMELLIA_KEY *key,
size_t length, const CAMELLIA_KEY *key,
unsigned char *ivec, int *num) {
unsigned int n;
unsigned long l=length;
assert(in && out && key && ivec && num);
n = *num;
while (l--) {
while (length--) {
if (n == 0) {
Camellia_encrypt(ivec, ivec, key);
}
......
......@@ -64,6 +64,8 @@
#error RC4 is disabled.
#endif
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -77,7 +79,7 @@ typedef struct rc4_key_st
const char *RC4_options(void);
void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
unsigned char *outdata);
#ifdef __cplusplus
......
......@@ -67,12 +67,12 @@
* Date: Wed, 14 Sep 1994 06:35:31 GMT
*/
void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
unsigned char *outdata)
{
register RC4_INT *d;
register RC4_INT x,y,tx,ty;
int i;
size_t i;
x=key->x;
y=key->y;
......@@ -120,8 +120,8 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
(RC4_CHUNK)d[(tx+ty)&0xff]\
)
if ( ( ((unsigned long)indata & (sizeof(RC4_CHUNK)-1)) |
((unsigned long)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
if ( ( ((size_t)indata & (sizeof(RC4_CHUNK)-1)) |
((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
{
RC4_CHUNK ichunk,otp;
const union { long one; char little; } is_endian = {1};
......@@ -276,7 +276,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
#endif
i=(int)(len>>3L);
i=len>>3;
if (i)
{
for (;;)
......@@ -296,7 +296,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
if (--i == 0) break;
}
}
i=(int)len&0x07;
i=len&0x07;
if (i)
{
for (;;)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册