CyaSSL is an SSL library for devices like mbed.

Dependents:   cyassl-client Sync

Committer:
toddouska
Date:
Sat Feb 05 01:09:17 2011 +0000
Revision:
0:5045d2638c29
Beta Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
toddouska 0:5045d2638c29 1 /* ctc_hmac.h
toddouska 0:5045d2638c29 2 *
toddouska 0:5045d2638c29 3 * Copyright (C) 2006-2009 Sawtooth Consulting Ltd.
toddouska 0:5045d2638c29 4 *
toddouska 0:5045d2638c29 5 * This file is part of CyaSSL.
toddouska 0:5045d2638c29 6 *
toddouska 0:5045d2638c29 7 * CyaSSL is free software; you can redistribute it and/or modify
toddouska 0:5045d2638c29 8 * it under the terms of the GNU General Public License as published by
toddouska 0:5045d2638c29 9 * the Free Software Foundation; either version 2 of the License, or
toddouska 0:5045d2638c29 10 * (at your option) any later version.
toddouska 0:5045d2638c29 11 *
toddouska 0:5045d2638c29 12 * CyaSSL is distributed in the hope that it will be useful,
toddouska 0:5045d2638c29 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
toddouska 0:5045d2638c29 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
toddouska 0:5045d2638c29 15 * GNU General Public License for more details.
toddouska 0:5045d2638c29 16 *
toddouska 0:5045d2638c29 17 * You should have received a copy of the GNU General Public License
toddouska 0:5045d2638c29 18 * along with this program; if not, write to the Free Software
toddouska 0:5045d2638c29 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
toddouska 0:5045d2638c29 20 */
toddouska 0:5045d2638c29 21
toddouska 0:5045d2638c29 22 #ifndef NO_HMAC
toddouska 0:5045d2638c29 23
toddouska 0:5045d2638c29 24 #ifndef CTAO_CRYPT_HMAC_H
toddouska 0:5045d2638c29 25 #define CTAO_CRYPT_HMAC_H
toddouska 0:5045d2638c29 26
toddouska 0:5045d2638c29 27 #include "ctc_md5.h"
toddouska 0:5045d2638c29 28 #include "ctc_sha.h"
toddouska 0:5045d2638c29 29
toddouska 0:5045d2638c29 30 #ifndef NO_SHA256
toddouska 0:5045d2638c29 31 #include "sha256.h"
toddouska 0:5045d2638c29 32 #endif
toddouska 0:5045d2638c29 33
toddouska 0:5045d2638c29 34 #ifdef __cplusplus
toddouska 0:5045d2638c29 35 extern "C" {
toddouska 0:5045d2638c29 36 #endif
toddouska 0:5045d2638c29 37
toddouska 0:5045d2638c29 38
toddouska 0:5045d2638c29 39
toddouska 0:5045d2638c29 40 enum {
toddouska 0:5045d2638c29 41 IPAD = 0x36,
toddouska 0:5045d2638c29 42 OPAD = 0x5C,
toddouska 0:5045d2638c29 43 #ifndef NO_SHA256
toddouska 0:5045d2638c29 44 INNER_HASH_SIZE = SHA256_DIGEST_SIZE,
toddouska 0:5045d2638c29 45 #else
toddouska 0:5045d2638c29 46 INNER_HASH_SIZE = SHA_DIGEST_SIZE,
toddouska 0:5045d2638c29 47 SHA256 = 2, /* hash type unique */
toddouska 0:5045d2638c29 48 #endif
toddouska 0:5045d2638c29 49 HMAC_BLOCK_SIZE = MD5_BLOCK_SIZE
toddouska 0:5045d2638c29 50 };
toddouska 0:5045d2638c29 51
toddouska 0:5045d2638c29 52
toddouska 0:5045d2638c29 53 /* hash union */
toddouska 0:5045d2638c29 54 typedef union {
toddouska 0:5045d2638c29 55 Md5 md5;
toddouska 0:5045d2638c29 56 Sha sha;
toddouska 0:5045d2638c29 57 #ifndef NO_SHA256
toddouska 0:5045d2638c29 58 Sha256 sha256;
toddouska 0:5045d2638c29 59 #endif
toddouska 0:5045d2638c29 60 } Hash;
toddouska 0:5045d2638c29 61
toddouska 0:5045d2638c29 62 /* Hmac digest */
toddouska 0:5045d2638c29 63 typedef struct Hmac {
toddouska 0:5045d2638c29 64 Hash hash;
toddouska 0:5045d2638c29 65 word32 ipad[HMAC_BLOCK_SIZE / sizeof(word32)]; /* same block size all*/
toddouska 0:5045d2638c29 66 word32 opad[HMAC_BLOCK_SIZE / sizeof(word32)];
toddouska 0:5045d2638c29 67 word32 innerHash[INNER_HASH_SIZE / sizeof(word32)]; /* max size */
toddouska 0:5045d2638c29 68 byte macType; /* md5 sha or sha256 */
toddouska 0:5045d2638c29 69 byte innerHashKeyed; /* keyed flag */
toddouska 0:5045d2638c29 70 } Hmac;
toddouska 0:5045d2638c29 71
toddouska 0:5045d2638c29 72
toddouska 0:5045d2638c29 73 void HmacSetKey(Hmac*, int type, const byte* key, word32 keySz); /* does init */
toddouska 0:5045d2638c29 74 void HmacUpdate(Hmac*, const byte*, word32);
toddouska 0:5045d2638c29 75 void HmacFinal(Hmac*, byte*);
toddouska 0:5045d2638c29 76
toddouska 0:5045d2638c29 77
toddouska 0:5045d2638c29 78 #ifdef __cplusplus
toddouska 0:5045d2638c29 79 } /* extern "C" */
toddouska 0:5045d2638c29 80 #endif
toddouska 0:5045d2638c29 81
toddouska 0:5045d2638c29 82 #endif /* CTAO_CRYPT_HMAC_H */
toddouska 0:5045d2638c29 83
toddouska 0:5045d2638c29 84 #endif /* NO_HMAC */
toddouska 0:5045d2638c29 85