[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openssl-cvs
Subject:    [CVS] OpenSSL: OpenSSL_0_9_7-stable: openssl/crypto/aes/ aes.h aes_cfb...
From:       "Ben Laurie" <ben () openssl ! org>
Date:       2003-07-27 13:46:57
[Download RAW message or body]

  OpenSSL CVS Repository
  http://cvs.openssl.org/
  ____________________________________________________________________________

  Server: cvs.openssl.org                  Name:   Ben Laurie
  Root:   /e/openssl/cvs                   Email:  ben@openssl.org
  Module: openssl                          Date:   27-Jul-2003 15:46:57
  Branch: OpenSSL_0_9_7-stable             Handle: 2003072714465700

  Modified files:           (Branch: OpenSSL_0_9_7-stable)
    openssl/crypto/aes      aes.h aes_cfb.c

  Log:
    Add untested CFB-r mode. Will be tested soon.

  Summary:
    Revision    Changes     Path
    1.1.2.5     +3  -0      openssl/crypto/aes/aes.h
    1.1.2.4     +57 -0      openssl/crypto/aes/aes_cfb.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openssl/crypto/aes/aes.h
  ============================================================================
  $ cvs diff -u -r1.1.2.4 -r1.1.2.5 aes.h
  --- openssl/crypto/aes/aes.h	3 Jul 2003 06:42:45 -0000	1.1.2.4
  +++ openssl/crypto/aes/aes.h	27 Jul 2003 13:46:57 -0000	1.1.2.5
  @@ -95,6 +95,9 @@
   void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
   	const unsigned long 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,
   	const unsigned long length, const AES_KEY *key,
   	unsigned char *ivec, int *num);
  @@ .
  patch -p0 <<'@@ .'
  Index: openssl/crypto/aes/aes_cfb.c
  ============================================================================
  $ cvs diff -u -r1.1.2.3 -r1.1.2.4 aes_cfb.c
  --- openssl/crypto/aes/aes_cfb.c	13 Nov 2002 14:01:18 -0000	1.1.2.3
  +++ openssl/crypto/aes/aes_cfb.c	27 Jul 2003 13:46:57 -0000	1.1.2.4
  @@ -155,3 +155,60 @@
   	*num=n;
   }
   
  +/* This expects a single block of size nbits for both in and out. Note that
  +   it corrupts any extra bits in the last byte of out */
  +/* Untested, once it is working, it will be optimised */
  +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)
  +    {
  +    unsigned int n;
  +    unsigned char ovec[AES_BLOCK_SIZE*2];
  +
  +    assert(in && out && key && ivec);
  +    if(enc)
  +	{
  +	/* construct the new IV in the second half of ovec */
  +	AES_encrypt(ivec,ovec+AES_BLOCK_SIZE,key);
  +	/* encrypt the input */
  +	for(n=0 ; n < (nbits+7)/8 ; ++n)
  +	    out[n]=in[n]^ovec[n+AES_BLOCK_SIZE];
  +	/* fill in the first half of the new IV with the current IV */
  +	memcpy(ovec,ivec,AES_BLOCK_SIZE);
  +	/* shift ovec left most of the bits... */
  +	memmove(ovec,ovec+nbits/8,AES_BLOCK_SIZE+(nbits%8 ? 1 : 0));
  +	/* now the remaining bits */
  +	if(nbits%8 != 0)
  +	    for(n=0 ; n < AES_BLOCK_SIZE ; ++n)
  +		{
  +		ovec[n]<<=nbits%8;
  +		ovec[n]|=ovec[n+1]>>(8-nbits%8);
  +		}
  +	/* finally, move it back into place */
  +	memcpy(ivec,ovec,AES_BLOCK_SIZE);
  +	}
  +    else
  +	{
  +	/* construct the new IV in the first half of ovec */
  +	AES_encrypt(ivec,ovec,key);
  +	/* decrypt the input */
  +	for(n=0 ; n < (nbits+7)/8 ; ++n)
  +	    out[n]=in[n]^ovec[n];
  +	/* fill in the first half of the new IV with the current IV */
  +	memcpy(ovec,ivec,AES_BLOCK_SIZE);
  +	/* append the ciphertext */
  +	memcpy(ovec+AES_BLOCK_SIZE,in,(nbits+7)/8);
  +	/* shift ovec left most of the bits... */
  +	memmove(ovec,ovec+nbits/8,AES_BLOCK_SIZE+(nbits%8 ? 1 : 0));
  +	/* now the remaining bits */
  +	if(nbits%8 != 0)
  +	    for(n=0 ; n < AES_BLOCK_SIZE ; ++n)
  +		{
  +		ovec[n]<<=nbits%8;
  +		ovec[n]|=ovec[n+1]>>(8-nbits%8);
  +		}
  +	/* finally, move it back into place */
  +	memcpy(ivec,ovec,AES_BLOCK_SIZE);
  +	}
  +    /* it is not necessary to cleanse ovec, since the IV is not secret */
  +    }
  @@ .
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
CVS Repository Commit List                     openssl-cvs@openssl.org
Automated List Manager                           majordomo@openssl.org
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic