Ignore:
Timestamp:
Jul 18, 2015, 5:06:52 PM (6 years ago)
Author:
katerina
Message:

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/rijndael-api-fst.h

    r230 r481  
    1 /*
    2  * rijndael-api-fst.h   v2.3   April '2000
     1/*      $NetBSD: rijndael-api-fst.h,v 1.8 2007/01/21 23:00:08 cbiere Exp $      */
     2
     3/**
     4 * rijndael-api-fst.h
    35 *
    4  * Optimised ANSI C code
     6 * @version 2.9 (December 2000)
    57 *
     8 * Optimised ANSI C code for the Rijndael cipher (now AES)
     9 *
     10 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
     11 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
     12 * @author Paulo Barreto <paulo.barreto@terra.com.br>
     13 *
     14 * This code is hereby placed in the public domain.
     15 *
     16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
     17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
     20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 *
     28 * Acknowledgements:
     29 *
     30 * We are deeply indebted to the following people for their bug reports,
     31 * fixes, and improvement suggestions to this implementation. Though we
     32 * tried to list all contributions, we apologise in advance for any
     33 * missing reference.
     34 *
     35 * Andrew Bales <Andrew.Bales@Honeywell.com>
     36 * Markus Friedl <markus.friedl@informatik.uni-erlangen.de>
     37 * John Skodon <skodonj@webquill.com>
    638 */
    739
     
    941#define __RIJNDAEL_API_FST_H
    1042
     43/* Blocksize: 16 * 8 = 128; 128 * 1 = 128 */
     44#define     B_SIZ    16
     45#define     BNUM      1
     46
     47
     48#if defined(UINT32)
     49typedef unsigned char u8;
     50typedef UINT32 u32;
     51#else
     52
     53typedef unsigned char u8;
     54#if defined(HAVE_INT_32)
     55typedef unsigned int u32;
     56#elif defined(HAVE_LONG_32)
     57typedef unsigned long u32;
     58#elif defined(HAVE_SHORT_32)
     59typedef unsigned short u32;
     60#else
     61#error "No 32 bit integer type found"
     62#endif
     63
     64#endif
     65
    1166#include "rijndael-alg-fst.h"
    1267
    13 /*  Defines:
    14     Add any additional defines you need
    15 */
    16 
    17 #define     BNUM                  1
    18 #define     B_SIZ                 16
    19 #define     STRICT_ALIGN          1 /*  For safety          */
    20 
    21 
     68/*  Generic Defines  */
    2269#define     DIR_ENCRYPT           0 /*  Are we encrpyting?  */
    2370#define     DIR_DECRYPT           1 /*  Are we decrpyting?  */
     
    3380#define     BITSPERBLOCK        128 /* Default number of bits in a cipher block */
    3481
    35 /*  Error Codes - CHANGE POSSIBLE: inclusion of additional error codes  */
    36 
     82/*  Error Codes  */
    3783#define     BAD_KEY_DIR          -1 /*  Key direction is invalid, e.g., unknown value */
    3884#define     BAD_KEY_MAT          -2 /*  Key material not of correct length */
     
    4591#define     BAD_OTHER            -9 /*  Unknown error */
    4692
    47 /*  CHANGE POSSIBLE:  inclusion of algorithm specific defines  */
    48 #define     MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
    49 #define     MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
     93/*  Algorithm-specific Defines  */
     94#define     RIJNDAEL_MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
     95#define     RIJNDAEL_MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
    5096
    5197#ifdef SH_ENCRYPT
    5298
    53 /*  Typedefs:
     99/*  Typedefs  */
    54100
    55         Typedef'ed data storage elements.  Add any algorithm specific
    56 parameters at the bottom of the structs as appropriate.
    57 */
    58 
    59 typedef unsigned char   RIJ_BYTE;
     101typedef unsigned char   BYTE;
    60102
    61103/*  The structure for key information */
    62104typedef struct {
    63     RIJ_BYTE  direction;                /* Key used for encrypting or decrypting? */
    64     int   keyLen;                   /* Length of the key  */
    65     char  keyMaterial[MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
    66         /*  The following parameters are algorithm dependent, replace or add as necessary  */
    67         int   ROUNDS;                   /* key-length-dependent number of rounds */
    68     int   blockLen;                 /* block length */
    69     word8 keySched[MAXROUNDS+1][4][4];  /* key schedule         */
     105  u32   rk[4*(RIJNDAEL_MAXNR + 1)];        /* key schedule */
     106  u32   ek[4*(RIJNDAEL_MAXNR + 1)];        /* CFB1 key schedule (encryption only) */
     107  BYTE  direction;                /* Key used for encrypting or decrypting? */
     108  int   keyLen;                   /* Length of the key  */
     109  char  keyMaterial[RIJNDAEL_MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
     110  int   Nr;                       /* key-length-dependent number of rounds */
    70111} keyInstance;
    71112
    72113/*  The structure for cipher information */
    73114typedef struct {                    /* changed order of the components */
    74     RIJ_BYTE  mode;                     /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
    75     RIJ_BYTE  IV[MAX_IV_SIZE];          /* A possible Initialization Vector for ciphering */
    76         /*  Add any algorithm specific parameters needed here  */
    77     int   blockLen;                 /* Sample: Handles non-128 bit block sizes (if available) */
     115    u32  IV[RIJNDAEL_MAX_IV_SIZE / sizeof(u32)];
     116                        /* A possible Initialization Vector for ciphering */
     117    BYTE  mode;                     /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
    78118} cipherInstance;
    79119
    80120/*  Function prototypes  */
    81 /*  CHANGED: nothing
    82         TODO: implement the following extensions to setup 192-bit and 256-bit block lengths:
    83         makeKeyEx():    parameter blockLen added
    84                         -- this parameter is absolutely necessary if you want to
    85                         setup the round keys in a variable block length setting
    86             cipherInitEx(): parameter blockLen added (for obvious reasons)             
    87  */
    88121
    89 int makeKey(keyInstance *key, RIJ_BYTE direction, int keyLen, char *keyMaterial);
     122int rijndael_makeKey(keyInstance *, BYTE, int, const char *);
    90123
    91 int cipherInit(cipherInstance *cipher, RIJ_BYTE mode, char *IV);
     124int rijndael_cipherInit(cipherInstance *, BYTE, const char *);
    92125
    93 int blockEncrypt(cipherInstance *cipher, keyInstance *key,
    94                  RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer);
     126int rijndael_blockEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
    95127
    96 int blockDecrypt(cipherInstance *cipher, keyInstance *key,
    97                  RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer);
    98 #ifdef INTERMEDIATE_VALUE_KAT
    99 int cipherUpdateRounds(cipherInstance *cipher, keyInstance *key,
    100                        RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer, int rounds);
    101 #endif
     128int rijndael_padEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
     129
     130int rijndael_blockDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
     131
     132int rijndael_padDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
    102133
    103134/* SH_ENCRYPT */
    104135#endif
    105 
    106 /*  __RIJNDAEL_API_FST_H */
    107 #endif
     136#endif /* __RIJNDAEL_API_FST_H */
Note: See TracChangeset for help on using the changeset viewer.