wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
Parent:
4:1b0d80432c79
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 4:1b0d80432c79 1 /*
wolfSSL 4:1b0d80432c79 2 BLAKE2 reference source code package - reference C implementations
wolfSSL 4:1b0d80432c79 3
wolfSSL 4:1b0d80432c79 4 Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
wolfSSL 4:1b0d80432c79 5
wolfSSL 4:1b0d80432c79 6 To the extent possible under law, the author(s) have dedicated all copyright
wolfSSL 4:1b0d80432c79 7 and related and neighboring rights to this software to the public domain
wolfSSL 4:1b0d80432c79 8 worldwide. This software is distributed without any warranty.
wolfSSL 4:1b0d80432c79 9
wolfSSL 4:1b0d80432c79 10 You should have received a copy of the CC0 Public Domain Dedication along with
wolfSSL 4:1b0d80432c79 11 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
wolfSSL 4:1b0d80432c79 12 */
wolfSSL 4:1b0d80432c79 13 /* blake2-int.h
wolfSSL 4:1b0d80432c79 14 *
wolfSSL 4:1b0d80432c79 15 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 4:1b0d80432c79 16 *
wolfSSL 4:1b0d80432c79 17 * This file is part of wolfSSL.
wolfSSL 4:1b0d80432c79 18 *
wolfSSL 4:1b0d80432c79 19 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 4:1b0d80432c79 20 * it under the terms of the GNU General Public License as published by
wolfSSL 4:1b0d80432c79 21 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 4:1b0d80432c79 22 * (at your option) any later version.
wolfSSL 4:1b0d80432c79 23 *
wolfSSL 4:1b0d80432c79 24 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 4:1b0d80432c79 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 4:1b0d80432c79 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 4:1b0d80432c79 27 * GNU General Public License for more details.
wolfSSL 4:1b0d80432c79 28 *
wolfSSL 4:1b0d80432c79 29 * You should have received a copy of the GNU General Public License
wolfSSL 4:1b0d80432c79 30 * along with this program; if not, write to the Free Software
wolfSSL 4:1b0d80432c79 31 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 4:1b0d80432c79 32 */
wolfSSL 4:1b0d80432c79 33
wolfSSL 4:1b0d80432c79 34
wolfSSL 4:1b0d80432c79 35
wolfSSL 4:1b0d80432c79 36
wolfSSL 4:1b0d80432c79 37 #ifndef WOLFCRYPT_BLAKE2_INT_H
wolfSSL 4:1b0d80432c79 38 #define WOLFCRYPT_BLAKE2_INT_H
wolfSSL 4:1b0d80432c79 39
wolfSSL 4:1b0d80432c79 40 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 4:1b0d80432c79 41
wolfSSL 4:1b0d80432c79 42
wolfSSL 4:1b0d80432c79 43 #if defined(_MSC_VER)
wolfSSL 4:1b0d80432c79 44 #define ALIGN(x) __declspec(align(x))
wolfSSL 4:1b0d80432c79 45 #elif defined(__GNUC__)
wolfSSL 4:1b0d80432c79 46 #define ALIGN(x) __attribute__((aligned(x)))
wolfSSL 4:1b0d80432c79 47 #else
wolfSSL 4:1b0d80432c79 48 #define ALIGN(x)
wolfSSL 4:1b0d80432c79 49 #endif
wolfSSL 4:1b0d80432c79 50
wolfSSL 4:1b0d80432c79 51
wolfSSL 4:1b0d80432c79 52 #if defined(__cplusplus)
wolfSSL 4:1b0d80432c79 53 extern "C" {
wolfSSL 4:1b0d80432c79 54 #endif
wolfSSL 4:1b0d80432c79 55
wolfSSL 4:1b0d80432c79 56 enum blake2s_constant
wolfSSL 4:1b0d80432c79 57 {
wolfSSL 4:1b0d80432c79 58 BLAKE2S_BLOCKBYTES = 64,
wolfSSL 4:1b0d80432c79 59 BLAKE2S_OUTBYTES = 32,
wolfSSL 4:1b0d80432c79 60 BLAKE2S_KEYBYTES = 32,
wolfSSL 4:1b0d80432c79 61 BLAKE2S_SALTBYTES = 8,
wolfSSL 4:1b0d80432c79 62 BLAKE2S_PERSONALBYTES = 8
wolfSSL 4:1b0d80432c79 63 };
wolfSSL 4:1b0d80432c79 64
wolfSSL 4:1b0d80432c79 65 enum blake2b_constant
wolfSSL 4:1b0d80432c79 66 {
wolfSSL 4:1b0d80432c79 67 BLAKE2B_BLOCKBYTES = 128,
wolfSSL 4:1b0d80432c79 68 BLAKE2B_OUTBYTES = 64,
wolfSSL 4:1b0d80432c79 69 BLAKE2B_KEYBYTES = 64,
wolfSSL 4:1b0d80432c79 70 BLAKE2B_SALTBYTES = 16,
wolfSSL 4:1b0d80432c79 71 BLAKE2B_PERSONALBYTES = 16
wolfSSL 4:1b0d80432c79 72 };
wolfSSL 4:1b0d80432c79 73
wolfSSL 4:1b0d80432c79 74 #pragma pack(push, 1)
wolfSSL 4:1b0d80432c79 75 typedef struct __blake2s_param
wolfSSL 4:1b0d80432c79 76 {
wolfSSL 4:1b0d80432c79 77 byte digest_length; /* 1 */
wolfSSL 4:1b0d80432c79 78 byte key_length; /* 2 */
wolfSSL 4:1b0d80432c79 79 byte fanout; /* 3 */
wolfSSL 4:1b0d80432c79 80 byte depth; /* 4 */
wolfSSL 4:1b0d80432c79 81 word32 leaf_length; /* 8 */
wolfSSL 4:1b0d80432c79 82 byte node_offset[6];/* 14 */
wolfSSL 4:1b0d80432c79 83 byte node_depth; /* 15 */
wolfSSL 4:1b0d80432c79 84 byte inner_length; /* 16 */
wolfSSL 4:1b0d80432c79 85 /* byte reserved[0]; */
wolfSSL 4:1b0d80432c79 86 byte salt[BLAKE2B_SALTBYTES]; /* 24 */
wolfSSL 4:1b0d80432c79 87 byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */
wolfSSL 4:1b0d80432c79 88 } blake2s_param;
wolfSSL 4:1b0d80432c79 89
wolfSSL 4:1b0d80432c79 90 ALIGN( 64 ) typedef struct __blake2s_state
wolfSSL 4:1b0d80432c79 91 {
wolfSSL 4:1b0d80432c79 92 word32 h[8];
wolfSSL 4:1b0d80432c79 93 word32 t[2];
wolfSSL 4:1b0d80432c79 94 word32 f[2];
wolfSSL 4:1b0d80432c79 95 byte buf[2 * BLAKE2S_BLOCKBYTES];
wolfSSL 4:1b0d80432c79 96 word64 buflen;
wolfSSL 4:1b0d80432c79 97 byte last_node;
wolfSSL 4:1b0d80432c79 98 } blake2s_state ;
wolfSSL 4:1b0d80432c79 99
wolfSSL 4:1b0d80432c79 100 typedef struct __blake2b_param
wolfSSL 4:1b0d80432c79 101 {
wolfSSL 4:1b0d80432c79 102 byte digest_length; /* 1 */
wolfSSL 4:1b0d80432c79 103 byte key_length; /* 2 */
wolfSSL 4:1b0d80432c79 104 byte fanout; /* 3 */
wolfSSL 4:1b0d80432c79 105 byte depth; /* 4 */
wolfSSL 4:1b0d80432c79 106 word32 leaf_length; /* 8 */
wolfSSL 4:1b0d80432c79 107 word64 node_offset; /* 16 */
wolfSSL 4:1b0d80432c79 108 byte node_depth; /* 17 */
wolfSSL 4:1b0d80432c79 109 byte inner_length; /* 18 */
wolfSSL 4:1b0d80432c79 110 byte reserved[14]; /* 32 */
wolfSSL 4:1b0d80432c79 111 byte salt[BLAKE2B_SALTBYTES]; /* 48 */
wolfSSL 4:1b0d80432c79 112 byte personal[BLAKE2B_PERSONALBYTES]; /* 64 */
wolfSSL 4:1b0d80432c79 113 } blake2b_param;
wolfSSL 4:1b0d80432c79 114
wolfSSL 4:1b0d80432c79 115 ALIGN( 64 ) typedef struct __blake2b_state
wolfSSL 4:1b0d80432c79 116 {
wolfSSL 4:1b0d80432c79 117 word64 h[8];
wolfSSL 4:1b0d80432c79 118 word64 t[2];
wolfSSL 4:1b0d80432c79 119 word64 f[2];
wolfSSL 4:1b0d80432c79 120 byte buf[2 * BLAKE2B_BLOCKBYTES];
wolfSSL 4:1b0d80432c79 121 word64 buflen;
wolfSSL 4:1b0d80432c79 122 byte last_node;
wolfSSL 4:1b0d80432c79 123 } blake2b_state;
wolfSSL 4:1b0d80432c79 124
wolfSSL 4:1b0d80432c79 125 typedef struct __blake2sp_state
wolfSSL 4:1b0d80432c79 126 {
wolfSSL 4:1b0d80432c79 127 blake2s_state S[8][1];
wolfSSL 4:1b0d80432c79 128 blake2s_state R[1];
wolfSSL 4:1b0d80432c79 129 byte buf[8 * BLAKE2S_BLOCKBYTES];
wolfSSL 4:1b0d80432c79 130 word64 buflen;
wolfSSL 4:1b0d80432c79 131 } blake2sp_state;
wolfSSL 4:1b0d80432c79 132
wolfSSL 4:1b0d80432c79 133 typedef struct __blake2bp_state
wolfSSL 4:1b0d80432c79 134 {
wolfSSL 4:1b0d80432c79 135 blake2b_state S[4][1];
wolfSSL 4:1b0d80432c79 136 blake2b_state R[1];
wolfSSL 4:1b0d80432c79 137 byte buf[4 * BLAKE2B_BLOCKBYTES];
wolfSSL 4:1b0d80432c79 138 word64 buflen;
wolfSSL 4:1b0d80432c79 139 } blake2bp_state;
wolfSSL 4:1b0d80432c79 140 #pragma pack(pop)
wolfSSL 4:1b0d80432c79 141
wolfSSL 4:1b0d80432c79 142 /* Streaming API */
wolfSSL 4:1b0d80432c79 143 int blake2s_init( blake2s_state *S, const byte outlen );
wolfSSL 4:1b0d80432c79 144 int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key, const byte keylen );
wolfSSL 4:1b0d80432c79 145 int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
wolfSSL 4:1b0d80432c79 146 int blake2s_update( blake2s_state *S, const byte *in, word64 inlen );
wolfSSL 4:1b0d80432c79 147 int blake2s_final( blake2s_state *S, byte *out, byte outlen );
wolfSSL 4:1b0d80432c79 148
wolfSSL 4:1b0d80432c79 149 int blake2b_init( blake2b_state *S, const byte outlen );
wolfSSL 4:1b0d80432c79 150 int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, const byte keylen );
wolfSSL 4:1b0d80432c79 151 int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
wolfSSL 4:1b0d80432c79 152 int blake2b_update( blake2b_state *S, const byte *in, word64 inlen );
wolfSSL 4:1b0d80432c79 153 int blake2b_final( blake2b_state *S, byte *out, byte outlen );
wolfSSL 4:1b0d80432c79 154
wolfSSL 4:1b0d80432c79 155 int blake2sp_init( blake2sp_state *S, const byte outlen );
wolfSSL 4:1b0d80432c79 156 int blake2sp_init_key( blake2sp_state *S, const byte outlen, const void *key, const byte keylen );
wolfSSL 4:1b0d80432c79 157 int blake2sp_update( blake2sp_state *S, const byte *in, word64 inlen );
wolfSSL 4:1b0d80432c79 158 int blake2sp_final( blake2sp_state *S, byte *out, byte outlen );
wolfSSL 4:1b0d80432c79 159
wolfSSL 4:1b0d80432c79 160 int blake2bp_init( blake2bp_state *S, const byte outlen );
wolfSSL 4:1b0d80432c79 161 int blake2bp_init_key( blake2bp_state *S, const byte outlen, const void *key, const byte keylen );
wolfSSL 4:1b0d80432c79 162 int blake2bp_update( blake2bp_state *S, const byte *in, word64 inlen );
wolfSSL 4:1b0d80432c79 163 int blake2bp_final( blake2bp_state *S, byte *out, byte outlen );
wolfSSL 4:1b0d80432c79 164
wolfSSL 4:1b0d80432c79 165 /* Simple API */
wolfSSL 4:1b0d80432c79 166 int blake2s( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
wolfSSL 4:1b0d80432c79 167 int blake2b( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
wolfSSL 4:1b0d80432c79 168
wolfSSL 4:1b0d80432c79 169 int blake2sp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
wolfSSL 4:1b0d80432c79 170 int blake2bp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
wolfSSL 4:1b0d80432c79 171
wolfSSL 4:1b0d80432c79 172 static INLINE int blake2( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen )
wolfSSL 4:1b0d80432c79 173 {
wolfSSL 4:1b0d80432c79 174 return blake2b( out, in, key, outlen, inlen, keylen );
wolfSSL 4:1b0d80432c79 175 }
wolfSSL 4:1b0d80432c79 176
wolfSSL 4:1b0d80432c79 177
wolfSSL 4:1b0d80432c79 178
wolfSSL 4:1b0d80432c79 179 #if defined(__cplusplus)
wolfSSL 4:1b0d80432c79 180 }
wolfSSL 4:1b0d80432c79 181 #endif
wolfSSL 4:1b0d80432c79 182
wolfSSL 4:1b0d80432c79 183 #endif /* WOLFCRYPT_BLAKE2_INT_H */
wolfSSL 4:1b0d80432c79 184
wolfSSL 4:1b0d80432c79 185