cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hmac.h Source File

hmac.h

00001 /* hmac.h
00002  *
00003  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00020  */
00021 
00022 
00023 #ifndef NO_HMAC
00024 
00025 #ifndef CTAO_CRYPT_HMAC_H
00026 #define CTAO_CRYPT_HMAC_H
00027 
00028 #ifndef NO_MD5
00029     #include <cyassl/ctaocrypt/md5.h>
00030 #endif
00031 
00032 #include <cyassl/ctaocrypt/sha.h>
00033 
00034 #ifndef NO_SHA256
00035     #include <cyassl/ctaocrypt/sha256.h>
00036 #endif
00037 
00038 #ifdef CYASSL_SHA384
00039     #include <cyassl/ctaocrypt/sha512.h>
00040 #endif
00041 
00042 #ifdef HAVE_CAVIUM
00043     #include <cyassl/ctaocrypt/logging.h>
00044     #include "cavium_common.h"
00045 #endif
00046 
00047 #ifdef __cplusplus
00048     extern "C" {
00049 #endif
00050 
00051 
00052 #define CYASSL_HMAC_CAVIUM_MAGIC 0xBEEF0005
00053 
00054 enum {
00055     IPAD    = 0x36,
00056     OPAD    = 0x5C,
00057 #ifdef NO_MD5
00058     MD5     = 0,
00059 #endif
00060 #if defined(CYASSL_SHA384)
00061     INNER_HASH_SIZE = SHA384_DIGEST_SIZE,
00062     HMAC_BLOCK_SIZE = SHA384_BLOCK_SIZE
00063 #elif !defined(NO_SHA256)
00064     INNER_HASH_SIZE = SHA256_DIGEST_SIZE,
00065     HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE,
00066     SHA384          = 5
00067 #else
00068     INNER_HASH_SIZE = SHA_DIGEST_SIZE,
00069     HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE,
00070     SHA256          = 2,                     /* hash type unique */
00071     SHA384          = 5
00072 #endif
00073 };
00074 
00075 
00076 /* hash union */
00077 typedef union {
00078     #ifndef NO_MD5
00079         Md5 md5;
00080     #endif
00081     Sha sha;
00082     #ifndef NO_SHA256
00083         Sha256 sha256;
00084     #endif
00085     #ifdef CYASSL_SHA384
00086         Sha384 sha384;
00087     #endif
00088 } Hash;
00089 
00090 /* Hmac digest */
00091 typedef struct Hmac {
00092     Hash    hash;
00093     word32  ipad[HMAC_BLOCK_SIZE  / sizeof(word32)];  /* same block size all*/
00094     word32  opad[HMAC_BLOCK_SIZE  / sizeof(word32)];
00095     word32  innerHash[INNER_HASH_SIZE / sizeof(word32)]; /* max size */
00096     byte    macType;                                     /* md5 sha or sha256 */
00097     byte    innerHashKeyed;                              /* keyed flag */
00098 #ifdef HAVE_CAVIUM
00099     word16   keyLen;          /* hmac key length */
00100     word16   dataLen;
00101     HashType type;            /* hmac key type */
00102     int      devId;           /* nitrox device id */
00103     word32   magic;           /* using cavium magic */
00104     word64   contextHandle;   /* nitrox context memory handle */
00105     byte*    data;            /* buffered input data for one call */
00106 #endif
00107 } Hmac;
00108 
00109 
00110 /* does init */
00111 CYASSL_API void HmacSetKey(Hmac*, int type, const byte* key, word32 keySz);
00112 CYASSL_API void HmacUpdate(Hmac*, const byte*, word32);
00113 CYASSL_API void HmacFinal(Hmac*, byte*);
00114 
00115 #ifdef HAVE_CAVIUM
00116     CYASSL_API int  HmacInitCavium(Hmac*, int);
00117     CYASSL_API void HmacFreeCavium(Hmac*);
00118 #endif
00119 
00120 
00121 #ifdef __cplusplus
00122     } /* extern "C" */
00123 #endif
00124 
00125 #endif /* CTAO_CRYPT_HMAC_H */
00126 
00127 #endif /* NO_HMAC */
00128