cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:54:58 2013 +0000
Revision:
0:e979170e02e7
Basic operation of SSL with PSK working for cellular.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:e979170e02e7 1 /* hmac.h
ashleymills 0:e979170e02e7 2 *
ashleymills 0:e979170e02e7 3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
ashleymills 0:e979170e02e7 4 *
ashleymills 0:e979170e02e7 5 * This file is part of CyaSSL.
ashleymills 0:e979170e02e7 6 *
ashleymills 0:e979170e02e7 7 * CyaSSL is free software; you can redistribute it and/or modify
ashleymills 0:e979170e02e7 8 * it under the terms of the GNU General Public License as published by
ashleymills 0:e979170e02e7 9 * the Free Software Foundation; either version 2 of the License, or
ashleymills 0:e979170e02e7 10 * (at your option) any later version.
ashleymills 0:e979170e02e7 11 *
ashleymills 0:e979170e02e7 12 * CyaSSL is distributed in the hope that it will be useful,
ashleymills 0:e979170e02e7 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ashleymills 0:e979170e02e7 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ashleymills 0:e979170e02e7 15 * GNU General Public License for more details.
ashleymills 0:e979170e02e7 16 *
ashleymills 0:e979170e02e7 17 * You should have received a copy of the GNU General Public License
ashleymills 0:e979170e02e7 18 * along with this program; if not, write to the Free Software
ashleymills 0:e979170e02e7 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ashleymills 0:e979170e02e7 20 */
ashleymills 0:e979170e02e7 21
ashleymills 0:e979170e02e7 22
ashleymills 0:e979170e02e7 23 #ifndef NO_HMAC
ashleymills 0:e979170e02e7 24
ashleymills 0:e979170e02e7 25 #ifndef CTAO_CRYPT_HMAC_H
ashleymills 0:e979170e02e7 26 #define CTAO_CRYPT_HMAC_H
ashleymills 0:e979170e02e7 27
ashleymills 0:e979170e02e7 28 #ifndef NO_MD5
ashleymills 0:e979170e02e7 29 #include <cyassl/ctaocrypt/md5.h>
ashleymills 0:e979170e02e7 30 #endif
ashleymills 0:e979170e02e7 31
ashleymills 0:e979170e02e7 32 #include <cyassl/ctaocrypt/sha.h>
ashleymills 0:e979170e02e7 33
ashleymills 0:e979170e02e7 34 #ifndef NO_SHA256
ashleymills 0:e979170e02e7 35 #include <cyassl/ctaocrypt/sha256.h>
ashleymills 0:e979170e02e7 36 #endif
ashleymills 0:e979170e02e7 37
ashleymills 0:e979170e02e7 38 #ifdef CYASSL_SHA384
ashleymills 0:e979170e02e7 39 #include <cyassl/ctaocrypt/sha512.h>
ashleymills 0:e979170e02e7 40 #endif
ashleymills 0:e979170e02e7 41
ashleymills 0:e979170e02e7 42 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 43 #include <cyassl/ctaocrypt/logging.h>
ashleymills 0:e979170e02e7 44 #include "cavium_common.h"
ashleymills 0:e979170e02e7 45 #endif
ashleymills 0:e979170e02e7 46
ashleymills 0:e979170e02e7 47 #ifdef __cplusplus
ashleymills 0:e979170e02e7 48 extern "C" {
ashleymills 0:e979170e02e7 49 #endif
ashleymills 0:e979170e02e7 50
ashleymills 0:e979170e02e7 51
ashleymills 0:e979170e02e7 52 #define CYASSL_HMAC_CAVIUM_MAGIC 0xBEEF0005
ashleymills 0:e979170e02e7 53
ashleymills 0:e979170e02e7 54 enum {
ashleymills 0:e979170e02e7 55 IPAD = 0x36,
ashleymills 0:e979170e02e7 56 OPAD = 0x5C,
ashleymills 0:e979170e02e7 57 #ifdef NO_MD5
ashleymills 0:e979170e02e7 58 MD5 = 0,
ashleymills 0:e979170e02e7 59 #endif
ashleymills 0:e979170e02e7 60 #if defined(CYASSL_SHA384)
ashleymills 0:e979170e02e7 61 INNER_HASH_SIZE = SHA384_DIGEST_SIZE,
ashleymills 0:e979170e02e7 62 HMAC_BLOCK_SIZE = SHA384_BLOCK_SIZE
ashleymills 0:e979170e02e7 63 #elif !defined(NO_SHA256)
ashleymills 0:e979170e02e7 64 INNER_HASH_SIZE = SHA256_DIGEST_SIZE,
ashleymills 0:e979170e02e7 65 HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE,
ashleymills 0:e979170e02e7 66 SHA384 = 5
ashleymills 0:e979170e02e7 67 #else
ashleymills 0:e979170e02e7 68 INNER_HASH_SIZE = SHA_DIGEST_SIZE,
ashleymills 0:e979170e02e7 69 HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE,
ashleymills 0:e979170e02e7 70 SHA256 = 2, /* hash type unique */
ashleymills 0:e979170e02e7 71 SHA384 = 5
ashleymills 0:e979170e02e7 72 #endif
ashleymills 0:e979170e02e7 73 };
ashleymills 0:e979170e02e7 74
ashleymills 0:e979170e02e7 75
ashleymills 0:e979170e02e7 76 /* hash union */
ashleymills 0:e979170e02e7 77 typedef union {
ashleymills 0:e979170e02e7 78 #ifndef NO_MD5
ashleymills 0:e979170e02e7 79 Md5 md5;
ashleymills 0:e979170e02e7 80 #endif
ashleymills 0:e979170e02e7 81 Sha sha;
ashleymills 0:e979170e02e7 82 #ifndef NO_SHA256
ashleymills 0:e979170e02e7 83 Sha256 sha256;
ashleymills 0:e979170e02e7 84 #endif
ashleymills 0:e979170e02e7 85 #ifdef CYASSL_SHA384
ashleymills 0:e979170e02e7 86 Sha384 sha384;
ashleymills 0:e979170e02e7 87 #endif
ashleymills 0:e979170e02e7 88 } Hash;
ashleymills 0:e979170e02e7 89
ashleymills 0:e979170e02e7 90 /* Hmac digest */
ashleymills 0:e979170e02e7 91 typedef struct Hmac {
ashleymills 0:e979170e02e7 92 Hash hash;
ashleymills 0:e979170e02e7 93 word32 ipad[HMAC_BLOCK_SIZE / sizeof(word32)]; /* same block size all*/
ashleymills 0:e979170e02e7 94 word32 opad[HMAC_BLOCK_SIZE / sizeof(word32)];
ashleymills 0:e979170e02e7 95 word32 innerHash[INNER_HASH_SIZE / sizeof(word32)]; /* max size */
ashleymills 0:e979170e02e7 96 byte macType; /* md5 sha or sha256 */
ashleymills 0:e979170e02e7 97 byte innerHashKeyed; /* keyed flag */
ashleymills 0:e979170e02e7 98 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 99 word16 keyLen; /* hmac key length */
ashleymills 0:e979170e02e7 100 word16 dataLen;
ashleymills 0:e979170e02e7 101 HashType type; /* hmac key type */
ashleymills 0:e979170e02e7 102 int devId; /* nitrox device id */
ashleymills 0:e979170e02e7 103 word32 magic; /* using cavium magic */
ashleymills 0:e979170e02e7 104 word64 contextHandle; /* nitrox context memory handle */
ashleymills 0:e979170e02e7 105 byte* data; /* buffered input data for one call */
ashleymills 0:e979170e02e7 106 #endif
ashleymills 0:e979170e02e7 107 } Hmac;
ashleymills 0:e979170e02e7 108
ashleymills 0:e979170e02e7 109
ashleymills 0:e979170e02e7 110 /* does init */
ashleymills 0:e979170e02e7 111 CYASSL_API void HmacSetKey(Hmac*, int type, const byte* key, word32 keySz);
ashleymills 0:e979170e02e7 112 CYASSL_API void HmacUpdate(Hmac*, const byte*, word32);
ashleymills 0:e979170e02e7 113 CYASSL_API void HmacFinal(Hmac*, byte*);
ashleymills 0:e979170e02e7 114
ashleymills 0:e979170e02e7 115 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 116 CYASSL_API int HmacInitCavium(Hmac*, int);
ashleymills 0:e979170e02e7 117 CYASSL_API void HmacFreeCavium(Hmac*);
ashleymills 0:e979170e02e7 118 #endif
ashleymills 0:e979170e02e7 119
ashleymills 0:e979170e02e7 120
ashleymills 0:e979170e02e7 121 #ifdef __cplusplus
ashleymills 0:e979170e02e7 122 } /* extern "C" */
ashleymills 0:e979170e02e7 123 #endif
ashleymills 0:e979170e02e7 124
ashleymills 0:e979170e02e7 125 #endif /* CTAO_CRYPT_HMAC_H */
ashleymills 0:e979170e02e7 126
ashleymills 0:e979170e02e7 127 #endif /* NO_HMAC */
ashleymills 0:e979170e02e7 128