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