CyaSSL 3.0.0

Dependents:   HTTPClient-SSL HTTPClient HTTPClient-SSL http_access ... more

Committer:
wolfSSL
Date:
Wed Dec 03 05:24:18 2014 +0000
Revision:
3:64d4f7cb83d5
Parent:
0:1239e9b70ca2
added IGNORE_KEY_EXTENSIONS

Who changed what in which revision?

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