1 /* 2 * Copyright (c) 2015-2018, Andrew Romanenko <melanhit@gmail.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef AKMOS_ALGO_THREEFISH_H 30 #define AKMOS_ALGO_THREEFISH_H 31 32 #define AKMOS_THREEFISH_256_BLKLEN 32 33 #define AKMOS_THREEFISH_256_KEYMIN 32 34 #define AKMOS_THREEFISH_256_KEYMAX 32 35 #define AKMOS_THREEFISH_256_KEYSTEP 32 36 37 #define AKMOS_THREEFISH_512_BLKLEN 64 38 #define AKMOS_THREEFISH_512_KEYMIN 64 39 #define AKMOS_THREEFISH_512_KEYMAX 64 40 #define AKMOS_THREEFISH_512_KEYSTEP 64 41 42 #define AKMOS_THREEFISH_1024_BLKLEN 128 43 #define AKMOS_THREEFISH_1024_KEYMIN 128 44 #define AKMOS_THREEFISH_1024_KEYMAX 128 45 #define AKMOS_THREEFISH_1024_KEYSTEP 128 46 47 #define AKMOS_THREEFISH_WORDS_256 4 48 #define AKMOS_THREEFISH_WORDS_512 8 49 #define AKMOS_THREEFISH_WORDS_1024 16 50 51 #define AKMOS_THREEFISH_C240 UINT64_C(0x1bd11bdaa9fc1a22) 52 53 typedef struct { 54 uint64_t S[AKMOS_THREEFISH_WORDS_256 * 19]; 55 uint64_t k[AKMOS_THREEFISH_WORDS_256 + 1]; 56 } akmos_threefish_256_t; 57 58 typedef struct { 59 uint64_t S[AKMOS_THREEFISH_WORDS_512 * 19]; 60 uint64_t k[AKMOS_THREEFISH_WORDS_512 + 1]; 61 } akmos_threefish_512_t; 62 63 typedef struct { 64 uint64_t S[AKMOS_THREEFISH_WORDS_1024 * 21]; 65 uint64_t k[AKMOS_THREEFISH_WORDS_1024 + 1]; 66 } akmos_threefish_1024_t; 67 68 void akmos_threefish_256_setkey (akmos_cipher_algo_t *, const uint8_t *, size_t); 69 void akmos_threefish_256_encrypt(akmos_cipher_algo_t *, const uint8_t *, uint8_t *); 70 void akmos_threefish_256_decrypt(akmos_cipher_algo_t *, const uint8_t *, uint8_t *); 71 72 void akmos_threefish_512_setkey (akmos_cipher_algo_t *, const uint8_t *, size_t); 73 void akmos_threefish_512_encrypt(akmos_cipher_algo_t *, const uint8_t *, uint8_t *); 74 void akmos_threefish_512_decrypt(akmos_cipher_algo_t *, const uint8_t *, uint8_t *); 75 76 void akmos_threefish_1024_setkey (akmos_cipher_algo_t *, const uint8_t *, size_t); 77 void akmos_threefish_1024_encrypt(akmos_cipher_algo_t *, const uint8_t *, uint8_t *); 78 void akmos_threefish_1024_decrypt(akmos_cipher_algo_t *, const uint8_t *, uint8_t *); 79 80 #endif /* AKMOS_ALGO_THREEFISH_H */ 81