Home | History | Annotate | Download | only in headers
      1 #ifdef LTC_HMAC
      2 typedef struct Hmac_state {
      3      hash_state     md;
      4      int            hash;
      5      hash_state     hashstate;
      6      unsigned char  *key;
      7 } hmac_state;
      8 
      9 int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
     10 int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
     11 int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
     12 int hmac_test(void);
     13 int hmac_memory(int hash,
     14                 const unsigned char *key, unsigned long keylen,
     15                 const unsigned char *in,  unsigned long inlen,
     16                       unsigned char *out, unsigned long *outlen);
     17 int hmac_memory_multi(int hash,
     18                 const unsigned char *key,  unsigned long keylen,
     19                       unsigned char *out,  unsigned long *outlen,
     20                 const unsigned char *in,   unsigned long inlen, ...);
     21 int hmac_file(int hash, const char *fname, const unsigned char *key,
     22               unsigned long keylen,
     23               unsigned char *dst, unsigned long *dstlen);
     24 #endif
     25 
     26 #ifdef LTC_OMAC
     27 
     28 typedef struct {
     29    int             cipher_idx,
     30                    buflen,
     31                    blklen;
     32    unsigned char   block[MAXBLOCKSIZE],
     33                    prev[MAXBLOCKSIZE],
     34                    Lu[2][MAXBLOCKSIZE];
     35    symmetric_key   key;
     36 } omac_state;
     37 
     38 int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
     39 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
     40 int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
     41 int omac_memory(int cipher,
     42                const unsigned char *key, unsigned long keylen,
     43                const unsigned char *in,  unsigned long inlen,
     44                      unsigned char *out, unsigned long *outlen);
     45 int omac_memory_multi(int cipher,
     46                 const unsigned char *key, unsigned long keylen,
     47                       unsigned char *out, unsigned long *outlen,
     48                 const unsigned char *in,  unsigned long inlen, ...);
     49 int omac_file(int cipher,
     50               const unsigned char *key, unsigned long keylen,
     51               const          char *filename,
     52                     unsigned char *out, unsigned long *outlen);
     53 int omac_test(void);
     54 #endif /* OMAC */
     55 
     56 #ifdef LTC_PMAC
     57 
     58 typedef struct {
     59    unsigned char     Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
     60                      Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
     61                      Lr[MAXBLOCKSIZE],        /* L * x^-1 */
     62                      block[MAXBLOCKSIZE],     /* currently accumulated block */
     63                      checksum[MAXBLOCKSIZE];  /* current checksum */
     64 
     65    symmetric_key     key;                     /* scheduled key for cipher */
     66    unsigned long     block_index;             /* index # for current block */
     67    int               cipher_idx,              /* cipher idx */
     68                      block_len,               /* length of block */
     69                      buflen;                  /* number of bytes in the buffer */
     70 } pmac_state;
     71 
     72 int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
     73 int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
     74 int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
     75 
     76 int pmac_memory(int cipher,
     77                const unsigned char *key, unsigned long keylen,
     78                const unsigned char *msg, unsigned long msglen,
     79                      unsigned char *out, unsigned long *outlen);
     80 
     81 int pmac_memory_multi(int cipher,
     82                 const unsigned char *key, unsigned long keylen,
     83                       unsigned char *out, unsigned long *outlen,
     84                 const unsigned char *in, unsigned long inlen, ...);
     85 
     86 int pmac_file(int cipher,
     87              const unsigned char *key, unsigned long keylen,
     88              const          char *filename,
     89                    unsigned char *out, unsigned long *outlen);
     90 
     91 int pmac_test(void);
     92 
     93 /* internal functions */
     94 int pmac_ntz(unsigned long x);
     95 void pmac_shift_xor(pmac_state *pmac);
     96 
     97 #endif /* PMAC */
     98 
     99 #ifdef EAX_MODE
    100 
    101 #if !(defined(LTC_OMAC) && defined(LTC_CTR_MODE))
    102    #error EAX_MODE requires OMAC and CTR
    103 #endif
    104 
    105 typedef struct {
    106    unsigned char N[MAXBLOCKSIZE];
    107    symmetric_CTR ctr;
    108    omac_state    headeromac, ctomac;
    109 } eax_state;
    110 
    111 int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
    112              const unsigned char *nonce, unsigned long noncelen,
    113              const unsigned char *header, unsigned long headerlen);
    114 
    115 int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
    116 int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
    117 int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
    118 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
    119 
    120 int eax_encrypt_authenticate_memory(int cipher,
    121     const unsigned char *key,    unsigned long keylen,
    122     const unsigned char *nonce,  unsigned long noncelen,
    123     const unsigned char *header, unsigned long headerlen,
    124     const unsigned char *pt,     unsigned long ptlen,
    125           unsigned char *ct,
    126           unsigned char *tag,    unsigned long *taglen);
    127 
    128 int eax_decrypt_verify_memory(int cipher,
    129     const unsigned char *key,    unsigned long keylen,
    130     const unsigned char *nonce,  unsigned long noncelen,
    131     const unsigned char *header, unsigned long headerlen,
    132     const unsigned char *ct,     unsigned long ctlen,
    133           unsigned char *pt,
    134           unsigned char *tag,    unsigned long taglen,
    135           int           *stat);
    136 
    137  int eax_test(void);
    138 #endif /* EAX MODE */
    139 
    140 #ifdef OCB_MODE
    141 typedef struct {
    142    unsigned char     L[MAXBLOCKSIZE],         /* L value */
    143                      Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
    144                      Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
    145                      Lr[MAXBLOCKSIZE],        /* L * x^-1 */
    146                      R[MAXBLOCKSIZE],         /* R value */
    147                      checksum[MAXBLOCKSIZE];  /* current checksum */
    148 
    149    symmetric_key     key;                     /* scheduled key for cipher */
    150    unsigned long     block_index;             /* index # for current block */
    151    int               cipher,                  /* cipher idx */
    152                      block_len;               /* length of block */
    153 } ocb_state;
    154 
    155 int ocb_init(ocb_state *ocb, int cipher,
    156              const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
    157 
    158 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
    159 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
    160 
    161 int ocb_done_encrypt(ocb_state *ocb,
    162                      const unsigned char *pt,  unsigned long ptlen,
    163                            unsigned char *ct,
    164                            unsigned char *tag, unsigned long *taglen);
    165 
    166 int ocb_done_decrypt(ocb_state *ocb,
    167                      const unsigned char *ct,  unsigned long ctlen,
    168                            unsigned char *pt,
    169                      const unsigned char *tag, unsigned long taglen, int *stat);
    170 
    171 int ocb_encrypt_authenticate_memory(int cipher,
    172     const unsigned char *key,    unsigned long keylen,
    173     const unsigned char *nonce,
    174     const unsigned char *pt,     unsigned long ptlen,
    175           unsigned char *ct,
    176           unsigned char *tag,    unsigned long *taglen);
    177 
    178 int ocb_decrypt_verify_memory(int cipher,
    179     const unsigned char *key,    unsigned long keylen,
    180     const unsigned char *nonce,
    181     const unsigned char *ct,     unsigned long ctlen,
    182           unsigned char *pt,
    183     const unsigned char *tag,    unsigned long taglen,
    184           int           *stat);
    185 
    186 int ocb_test(void);
    187 
    188 /* internal functions */
    189 void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
    190 int ocb_ntz(unsigned long x);
    191 int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
    192                unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
    193 
    194 #endif /* OCB_MODE */
    195 
    196 #ifdef CCM_MODE
    197 
    198 #define CCM_ENCRYPT 0
    199 #define CCM_DECRYPT 1
    200 
    201 int ccm_memory(int cipher,
    202     const unsigned char *key,    unsigned long keylen,
    203     symmetric_key       *uskey,
    204     const unsigned char *nonce,  unsigned long noncelen,
    205     const unsigned char *header, unsigned long headerlen,
    206           unsigned char *pt,     unsigned long ptlen,
    207           unsigned char *ct,
    208           unsigned char *tag,    unsigned long *taglen,
    209                     int  direction);
    210 
    211 int ccm_test(void);
    212 
    213 #endif /* CCM_MODE */
    214 
    215 #if defined(LRW_MODE) || defined(GCM_MODE)
    216 void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c);
    217 #endif
    218 
    219 
    220 /* table shared between GCM and LRW */
    221 #if defined(GCM_TABLES) || defined(LRW_TABLES) || ((defined(GCM_MODE) || defined(GCM_MODE)) && defined(LTC_FAST))
    222 extern const unsigned char gcm_shift_table[];
    223 #endif
    224 
    225 #ifdef GCM_MODE
    226 
    227 #define GCM_ENCRYPT 0
    228 #define GCM_DECRYPT 1
    229 
    230 #define GCM_MODE_IV    0
    231 #define GCM_MODE_AAD   1
    232 #define GCM_MODE_TEXT  2
    233 
    234 typedef struct {
    235    symmetric_key       K;
    236    unsigned char       H[16],        /* multiplier */
    237                        X[16],        /* accumulator */
    238                        Y[16],        /* counter */
    239                        Y_0[16],      /* initial counter */
    240                        buf[16];      /* buffer for stuff */
    241 
    242    int                 cipher,       /* which cipher */
    243                        ivmode,       /* Which mode is the IV in? */
    244                        mode,         /* mode the GCM code is in */
    245                        buflen;       /* length of data in buf */
    246 
    247    ulong64             totlen,       /* 64-bit counter used for IV and AAD */
    248                        pttotlen;     /* 64-bit counter for the PT */
    249 
    250 #ifdef GCM_TABLES
    251    unsigned char       PC[16][256][16]  /* 16 tables of 8x128 */
    252 #ifdef GCM_TABLES_SSE2
    253 __attribute__ ((aligned (16)))
    254 #endif
    255 ;
    256 #endif
    257 } gcm_state;
    258 
    259 void gcm_mult_h(gcm_state *gcm, unsigned char *I);
    260 
    261 int gcm_init(gcm_state *gcm, int cipher,
    262              const unsigned char *key, int keylen);
    263 
    264 int gcm_reset(gcm_state *gcm);
    265 
    266 int gcm_add_iv(gcm_state *gcm,
    267                const unsigned char *IV,     unsigned long IVlen);
    268 
    269 int gcm_add_aad(gcm_state *gcm,
    270                const unsigned char *adata,  unsigned long adatalen);
    271 
    272 int gcm_process(gcm_state *gcm,
    273                      unsigned char *pt,     unsigned long ptlen,
    274                      unsigned char *ct,
    275                      int direction);
    276 
    277 int gcm_done(gcm_state *gcm,
    278                      unsigned char *tag,    unsigned long *taglen);
    279 
    280 int gcm_memory(      int           cipher,
    281                const unsigned char *key,    unsigned long keylen,
    282                const unsigned char *IV,     unsigned long IVlen,
    283                const unsigned char *adata,  unsigned long adatalen,
    284                      unsigned char *pt,     unsigned long ptlen,
    285                      unsigned char *ct,
    286                      unsigned char *tag,    unsigned long *taglen,
    287                                int direction);
    288 int gcm_test(void);
    289 
    290 #endif /* GCM_MODE */
    291 
    292 #ifdef PELICAN
    293 
    294 typedef struct pelican_state
    295 {
    296     symmetric_key K;
    297     unsigned char state[16];
    298     int           buflen;
    299 } pelican_state;
    300 
    301 int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen);
    302 int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen);
    303 int pelican_done(pelican_state *pelmac, unsigned char *out);
    304 int pelican_test(void);
    305 
    306 int pelican_memory(const unsigned char *key, unsigned long keylen,
    307                    const unsigned char *in, unsigned long inlen,
    308                          unsigned char *out);
    309 
    310 #endif
    311 
    312 #ifdef LTC_XCBC
    313 
    314 typedef struct {
    315    unsigned char K[3][MAXBLOCKSIZE],
    316                  IV[MAXBLOCKSIZE];
    317 
    318    symmetric_key key;
    319 
    320              int cipher,
    321                  buflen,
    322                  blocksize;
    323 } xcbc_state;
    324 
    325 int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen);
    326 int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen);
    327 int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen);
    328 int xcbc_memory(int cipher,
    329                const unsigned char *key, unsigned long keylen,
    330                const unsigned char *in,  unsigned long inlen,
    331                      unsigned char *out, unsigned long *outlen);
    332 int xcbc_memory_multi(int cipher,
    333                 const unsigned char *key, unsigned long keylen,
    334                       unsigned char *out, unsigned long *outlen,
    335                 const unsigned char *in,  unsigned long inlen, ...);
    336 int xcbc_file(int cipher,
    337               const unsigned char *key, unsigned long keylen,
    338               const          char *filename,
    339                     unsigned char *out, unsigned long *outlen);
    340 int xcbc_test(void);
    341 
    342 #endif
    343 
    344 #ifdef LTC_F9_MODE
    345 
    346 typedef struct {
    347    unsigned char akey[MAXBLOCKSIZE],
    348                  ACC[MAXBLOCKSIZE],
    349                  IV[MAXBLOCKSIZE];
    350 
    351    symmetric_key key;
    352 
    353              int cipher,
    354                  buflen,
    355                  keylen,
    356                  blocksize;
    357 } f9_state;
    358 
    359 int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen);
    360 int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen);
    361 int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen);
    362 int f9_memory(int cipher,
    363                const unsigned char *key, unsigned long keylen,
    364                const unsigned char *in,  unsigned long inlen,
    365                      unsigned char *out, unsigned long *outlen);
    366 int f9_memory_multi(int cipher,
    367                 const unsigned char *key, unsigned long keylen,
    368                       unsigned char *out, unsigned long *outlen,
    369                 const unsigned char *in,  unsigned long inlen, ...);
    370 int f9_file(int cipher,
    371               const unsigned char *key, unsigned long keylen,
    372               const          char *filename,
    373                     unsigned char *out, unsigned long *outlen);
    374 int f9_test(void);
    375 
    376 #endif
    377 
    378 
    379 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_mac.h,v $ */
    380 /* $Revision: 1.20 $ */
    381 /* $Date: 2006/11/08 21:57:04 $ */
    382