Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hmac.h Source File

hmac.h

Go to the documentation of this file.
00001 /**
00002  * @file hmac.h
00003  * @brief HMAC (Keyed-Hashing for Message Authentication)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneCrypto Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _HMAC_H
00030 #define _HMAC_H
00031 
00032 //Dependencies
00033 #include "crypto.h"
00034 
00035 //MD2 hash support?
00036 #if (MD2_SUPPORT == ENABLED)
00037    #include "md2.h"
00038 #endif
00039 
00040 //MD4 hash support?
00041 #if (MD4_SUPPORT == ENABLED)
00042    #include "md4.h"
00043 #endif
00044 
00045 //MD5 hash support?
00046 #if (MD5_SUPPORT == ENABLED)
00047    #include "md5.h"
00048 #endif
00049 
00050 //RIPEMD-128 hash support?
00051 #if (RIPEMD128_SUPPORT == ENABLED)
00052    #include "ripemd128.h"
00053 #endif
00054 
00055 //RIPEMD-160 hash support?
00056 #if (RIPEMD160_SUPPORT == ENABLED)
00057    #include "ripemd160.h"
00058 #endif
00059 
00060 //SHA-1 hash support?
00061 #if (SHA1_SUPPORT == ENABLED)
00062    #include "sha1.h"
00063 #endif
00064 
00065 //SHA-224 hash support?
00066 #if (SHA224_SUPPORT == ENABLED)
00067    #include "sha224.h"
00068 #endif
00069 
00070 //SHA-256 hash support?
00071 #if (SHA256_SUPPORT == ENABLED)
00072    #include "sha256.h"
00073 #endif
00074 
00075 //SHA-384 hash support?
00076 #if (SHA384_SUPPORT == ENABLED)
00077    #include "sha384.h"
00078 #endif
00079 
00080 //SHA-512 hash support?
00081 #if (SHA512_SUPPORT == ENABLED)
00082    #include "sha512.h"
00083 #endif
00084 
00085 //SHA-512/224 hash support?
00086 #if (SHA512_224_SUPPORT == ENABLED)
00087    #include "sha512_224.h"
00088 #endif
00089 
00090 //SHA-512/256 hash support?
00091 #if (SHA512_256_SUPPORT == ENABLED)
00092    #include "sha512_256.h"
00093 #endif
00094 
00095 //SHA3-224 hash support?
00096 #if (SHA3_224_SUPPORT == ENABLED)
00097    #include "sha3_224.h"
00098 #endif
00099 
00100 //SHA3-256 hash support?
00101 #if (SHA3_256_SUPPORT == ENABLED)
00102    #include "sha3_256.h"
00103 #endif
00104 
00105 //SHA3-384 hash support?
00106 #if (SHA3_384_SUPPORT == ENABLED)
00107    #include "sha3_384.h"
00108 #endif
00109 
00110 //SHA3-512 hash support?
00111 #if (SHA3_512_SUPPORT == ENABLED)
00112    #include "sha3_512.h"
00113 #endif
00114 
00115 //Tiger hash support?
00116 #if (TIGER_SUPPORT == ENABLED)
00117    #include "tiger.h"
00118 #endif
00119 
00120 //Whirlpool hash support?
00121 #if (WHIRLPOOL_SUPPORT == ENABLED)
00122    #include "whirlpool.h"
00123 #endif
00124 
00125 //Inner padding (ipad)
00126 #define HMAC_IPAD 0x36
00127 //Outer padding (opad)
00128 #define HMAC_OPAD 0x5C
00129 
00130 
00131 /**
00132  * @brief HMAC algorithm context
00133  **/
00134 
00135 typedef struct
00136 {
00137    const HashAlgo *hash;
00138    uint8_t hashContext[MAX_HASH_CONTEXT_SIZE];
00139    uint8_t key[MAX_HASH_BLOCK_SIZE];
00140    uint8_t digest[MAX_HASH_DIGEST_SIZE];
00141 } HmacContext;
00142 
00143 
00144 //HMAC related constants
00145 extern const uint8_t HMAC_WITH_MD5_OID[8];
00146 extern const uint8_t HMAC_WITH_TIGER_OID[8];
00147 extern const uint8_t HMAC_WITH_RIPEMD160_OID[8];
00148 extern const uint8_t HMAC_WITH_SHA1_OID[8];
00149 extern const uint8_t HMAC_WITH_SHA224_OID[8];
00150 extern const uint8_t HMAC_WITH_SHA256_OID[8];
00151 extern const uint8_t HMAC_WITH_SHA384_OID[8];
00152 extern const uint8_t HMAC_WITH_SHA512_OID[8];
00153 extern const uint8_t HMAC_WITH_SHA3_224_OID[9];
00154 extern const uint8_t HMAC_WITH_SHA3_256_OID[9];
00155 extern const uint8_t HMAC_WITH_SHA3_384_OID[9];
00156 extern const uint8_t HMAC_WITH_SHA3_512_OID[9];
00157 
00158 //HMAC related functions
00159 error_t hmacCompute(const HashAlgo *hash, const void *key, size_t keyLength,
00160    const void *data, size_t dataLength, uint8_t *digest);
00161 
00162 void hmacInit(HmacContext *context, const HashAlgo *hash,
00163    const void *key, size_t length);
00164 
00165 void hmacUpdate(HmacContext *context, const void *data, size_t length);
00166 void hmacFinal(HmacContext *context, uint8_t *digest);
00167 
00168 #endif
00169