Commit 259810e0 authored by Ben Laurie's avatar Ben Laurie
Browse files

Rijdael CBC mode and partial undebugged SSL support.

parent 171cc53a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -442,6 +442,9 @@ bad:

	if (cipher != NULL)
		{
		/* Note that str is NULL if a key was passed on the command
		 * line, so we get no salt in that case. Is this a bug?
		 */
		if (str != NULL)
			{
			/* Salt handling: if encrypting generate a salt and
+3 −0
Original line number Diff line number Diff line
@@ -150,7 +150,10 @@ void OpenSSL_add_all_ciphers(void)
#ifndef NO_RIJNDAEL
	for(i=0 ; i < 3 ; ++i)
	    for(j=0 ; j < 3 ; ++j)
		{
		EVP_add_cipher(EVP_rijndael_ecb(i,j));
		EVP_add_cipher(EVP_rijndael_cbc(i,j));
		}
#endif
	PKCS12_PBE_add();
	PKCS5_PBE_add();
+77 −5
Original line number Diff line number Diff line
@@ -56,14 +56,21 @@
static EVP_CIPHER rd_cipher[3][3];

static int anSizes[]={16,24,32};
static int anNIDs[3][3]=
static int anECBNIDs[3][3]=
    {
    { NID_rijndael_ecb_k128_b128,NID_rijndael_ecb_k192_b128,NID_rijndael_ecb_k256_b128 },
    { NID_rijndael_ecb_k128_b192,NID_rijndael_ecb_k192_b192,NID_rijndael_ecb_k256_b192 },
    { NID_rijndael_ecb_k128_b256,NID_rijndael_ecb_k192_b256,NID_rijndael_ecb_k256_b256 }
    };

static int rd_init_ecb(EVP_CIPHER_CTX *ctx, const unsigned char *key,
static int anCBCNIDs[3][3]=
    {
    { NID_rd128_cbc_b128,NID_rd192_cbc_b128,NID_rd256_cbc_b128 },
    { NID_rd128_cbc_b192,NID_rd192_cbc_b192,NID_rd256_cbc_b192 },
    { NID_rd128_cbc_b256,NID_rd192_cbc_b256,NID_rd256_cbc_b256 }
    };

static int rd_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
		   const unsigned char *iv, int enc)
    {
    RIJNDAEL_KEY *k=&ctx->c.rijndael;
@@ -98,6 +105,39 @@ static int rd_cipher_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out,
    return 1;
    }

static int rd_cipher_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
			 const unsigned char *in, unsigned int inl)
    {
    int n;
    unsigned char tmp[16];

    while(inl > 0)
	{
	if(ctx->c.rijndael.enc)
	    {
	    for(n=0 ; n < 16 ; ++n)
		tmp[n]=in[n]^ctx->c.rijndael.iv[n];
	    rijndaelEncrypt(tmp,out,ctx->c.rijndael.keySched,
			    ctx->c.rijndael.rounds);
	    memcpy(ctx->c.rijndael.iv,out,16);
	    }
	else
	    {
	    rijndaelDecrypt(in,out,ctx->c.rijndael.keySched,
			    ctx->c.rijndael.rounds);
	    for(n=0 ; n < 16 ; ++n)
		out[n]^=ctx->c.rijndael.iv[n];
	    memcpy(ctx->c.rijndael.iv,in,16);
	    }
	inl-=16;
	in+=16;
	out+=16;
	}
    assert(inl == 0);

    return 1;
    }

EVP_CIPHER *EVP_rijndael_ecb(int nBlockLength,int nKeyLength)
    {
    EVP_CIPHER *c;
@@ -117,15 +157,47 @@ EVP_CIPHER *EVP_rijndael_ecb(int nBlockLength,int nKeyLength)

    memset(c,'\0',sizeof *c);

    c->nid=anNIDs[nBlockLength][nKeyLength];
    c->nid=anECBNIDs[nBlockLength][nKeyLength];
    c->block_size=anSizes[nBlockLength];
    c->key_len=anSizes[nKeyLength];
    c->iv_len=16;
    c->flags=EVP_CIPH_ECB_MODE;
    c->init=rd_init_ecb;
    c->init=rd_init;
    c->do_cipher=rd_cipher_ecb;
    c->ctx_size=sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
		sizeof((((EVP_CIPHER_CTX *)NULL)->c.rijndael));

    return c;
    }

EVP_CIPHER *EVP_rijndael_cbc(int nBlockLength,int nKeyLength)
    {
    EVP_CIPHER *c;

    if(nBlockLength < 0 || nBlockLength > 2)
	{
	EVPerr(EVP_F_EVP_RIJNDAEL,EVP_R_BAD_BLOCK_LENGTH);
	return NULL;
	}
    if(nKeyLength < 0 || nKeyLength > 2)
	{
	EVPerr(EVP_F_EVP_RIJNDAEL,EVP_R_BAD_KEY_LENGTH);
	return NULL;
	}

    c=&rd_cipher[nKeyLength][nBlockLength];

    memset(c,'\0',sizeof *c);

    c->nid=anCBCNIDs[nBlockLength][nKeyLength];
    c->block_size=anSizes[nBlockLength];
    c->key_len=anSizes[nKeyLength];
    c->iv_len=16;
    c->flags=EVP_CIPH_CBC_MODE;
    c->init=rd_init;
    c->do_cipher=rd_cipher_cbc;
    c->ctx_size=sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
		sizeof((((EVP_CIPHER_CTX *)NULL)->c.rijndael));

    return c;
    }
+1 −0
Original line number Diff line number Diff line
@@ -707,6 +707,7 @@ EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
#endif
#ifndef NO_RIJNDAEL
EVP_CIPHER *EVP_rijndael_ecb(int nBlockLength,int nKeyLength);
EVP_CIPHER *EVP_rijndael_cbc(int nBlockLength,int nKeyLength);
#endif

void OpenSSL_add_all_algorithms(void);
+33 −3
Original line number Diff line number Diff line
@@ -61,9 +61,9 @@
 * perl obj_dat.pl objects.h obj_dat.h
 */

#define NUM_NID 405
#define NUM_SN 401
#define NUM_LN 401
#define NUM_NID 417
#define NUM_SN 410
#define NUM_LN 410
#define NUM_OBJ 366

static unsigned char lvalues[2896]={
@@ -1066,6 +1066,18 @@ static ASN1_OBJECT nid_objs[NUM_NID]={
	NID_rijndael_ecb_k192_b256,0,NULL},
{"RIJNDAEL-ECB-K256-B256","rijndael-ecb-k256-b256",
	NID_rijndael_ecb_k256_b256,0,NULL},
{NULL,NULL,NID_undef,0,NULL},
{NULL,NULL,NID_undef,0,NULL},
{NULL,NULL,NID_undef,0,NULL},
{"RD128-CBC-B128","rd128-cbc-b128",NID_rd128_cbc_b128,0,NULL},
{"RD192-CBC-B128","rd192-cbc-b128",NID_rd192_cbc_b128,0,NULL},
{"RD256-CBC-B128","rd256-cbc-b128",NID_rd256_cbc_b128,0,NULL},
{"RD128-CBC-B192","rd128-cbc-b192",NID_rd128_cbc_b192,0,NULL},
{"RD192-CBC-B192","rd192-cbc-b192",NID_rd192_cbc_b192,0,NULL},
{"RD256-CBC-B192","rd256-cbc-b192",NID_rd256_cbc_b192,0,NULL},
{"RD128-CBC-B256","rd128-cbc-b256",NID_rd128_cbc_b256,0,NULL},
{"RD192-CBC-B256","rd192-cbc-b256",NID_rd192_cbc_b256,0,NULL},
{"RD256-CBC-B256","rd256-cbc-b256",NID_rd256_cbc_b256,0,NULL},
};

static ASN1_OBJECT *sn_objs[NUM_SN]={
@@ -1155,6 +1167,15 @@ static ASN1_OBJECT *sn_objs[NUM_SN]={
&(nid_objs[122]),/* "RC5-CFB" */
&(nid_objs[121]),/* "RC5-ECB" */
&(nid_objs[123]),/* "RC5-OFB" */
&(nid_objs[408]),/* "RD128-CBC-B128" */
&(nid_objs[411]),/* "RD128-CBC-B192" */
&(nid_objs[414]),/* "RD128-CBC-B256" */
&(nid_objs[409]),/* "RD192-CBC-B128" */
&(nid_objs[412]),/* "RD192-CBC-B192" */
&(nid_objs[415]),/* "RD192-CBC-B256" */
&(nid_objs[410]),/* "RD256-CBC-B128" */
&(nid_objs[413]),/* "RD256-CBC-B192" */
&(nid_objs[416]),/* "RD256-CBC-B256" */
&(nid_objs[396]),/* "RIJNDAEL-ECB-K128-B128" */
&(nid_objs[399]),/* "RIJNDAEL-ECB-K128-B192" */
&(nid_objs[402]),/* "RIJNDAEL-ECB-K128-B256" */
@@ -1834,6 +1855,15 @@ static ASN1_OBJECT *ln_objs[NUM_LN]={
&(nid_objs[122]),/* "rc5-cfb" */
&(nid_objs[121]),/* "rc5-ecb" */
&(nid_objs[123]),/* "rc5-ofb" */
&(nid_objs[408]),/* "rd128-cbc-b128" */
&(nid_objs[411]),/* "rd128-cbc-b192" */
&(nid_objs[414]),/* "rd128-cbc-b256" */
&(nid_objs[409]),/* "rd192-cbc-b128" */
&(nid_objs[412]),/* "rd192-cbc-b192" */
&(nid_objs[415]),/* "rd192-cbc-b256" */
&(nid_objs[410]),/* "rd256-cbc-b128" */
&(nid_objs[413]),/* "rd256-cbc-b192" */
&(nid_objs[416]),/* "rd256-cbc-b256" */
&(nid_objs[396]),/* "rijndael-ecb-k128-b128" */
&(nid_objs[399]),/* "rijndael-ecb-k128-b192" */
&(nid_objs[402]),/* "rijndael-ecb-k128-b256" */
Loading