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