Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
keccak.h
00001 /** 00002 * @file keccak.h 00003 * @brief Keccak sponge function 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneCrypto Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _KECCAK_H 00030 #define _KECCAK_H 00031 00032 //Dependencies 00033 #include "crypto.h" 00034 00035 //The binary logarithm of the lane size 00036 #ifndef KECCAK_L 00037 #define KECCAK_L 6 00038 #endif 00039 00040 //Check lane size 00041 #if (KECCAK_L == 3) 00042 //Base type that represents a lane 00043 typedef uint8_t keccak_lane_t; 00044 //Rotate left operation 00045 #define KECCAK_ROL(a, n) ROL8(a, n) 00046 //Host byte order to little-endian byte order 00047 #define KECCAK_HTOLE(a) (a) 00048 //Little-endian byte order to host byte order 00049 #define KECCAK_LETOH(a) (a) 00050 #elif (KECCAK_L == 4) 00051 //Base type that represents a lane 00052 #define keccak_lane_t uint16_t 00053 //Rotate left operation 00054 #define KECCAK_ROL(a, n) ROL16(a, n) 00055 //Host byte order to little-endian byte order 00056 #define KECCAK_HTOLE(a) htole16(a) 00057 //Little-endian byte order to host byte order 00058 #define KECCAK_LETOH(a) letoh16(a) 00059 #elif (KECCAK_L == 5) 00060 //Base type that represents a lane 00061 #define keccak_lane_t uint32_t 00062 //Rotate left operation 00063 #define KECCAK_ROL(a, n) ROL32(a, n) 00064 //Host byte order to little-endian byte order 00065 #define KECCAK_HTOLE(a) htole32(a) 00066 //Little-endian byte order to host byte order 00067 #define KECCAK_LETOH(a) letoh32(a) 00068 #elif (KECCAK_L == 6) 00069 //Base type that represents a lane 00070 #define keccak_lane_t uint64_t 00071 //Rotate left operation 00072 #define KECCAK_ROL(a, n) ROL64(a, n) 00073 //Host byte order to little-endian byte order conversion 00074 #define KECCAK_HTOLE(a) htole64(a) 00075 //Little-endian byte order to host byte order conversion 00076 #define KECCAK_LETOH(a) letoh64(a) 00077 #else 00078 #error KECCAK_L parameter is not valid 00079 #endif 00080 00081 //The lane size of a Keccak-p permutation in bits 00082 #define KECCAK_W (1 << KECCAK_L) 00083 //The width of a Keccak-p permutation 00084 #define KECCAK_B (KECCAK_W * 25) 00085 //The number of rounds for a Keccak-p permutation 00086 #define KECCAK_NR (12 + 2 * KECCAK_L) 00087 00088 00089 /** 00090 * @brief Keccak context 00091 **/ 00092 00093 typedef struct 00094 { 00095 union 00096 { 00097 keccak_lane_t a[5][5]; 00098 uint8_t digest[1]; 00099 }; 00100 union 00101 { 00102 keccak_lane_t block[24]; 00103 uint8_t buffer[1]; 00104 }; 00105 uint_t blockSize; 00106 size_t length; 00107 } KeccakContext; 00108 00109 00110 //Keccak related functions 00111 error_t keccakInit(KeccakContext *context, uint_t capacity); 00112 void keccakAbsorb(KeccakContext *context, const void *input, size_t length); 00113 void keccakFinal(KeccakContext *context, uint8_t pad); 00114 void keccakSqueeze(KeccakContext *context, uint8_t *output, size_t length); 00115 void keccakPermutBlock(KeccakContext *context); 00116 00117 #endif 00118
Generated on Tue Jul 12 2022 17:10:14 by
1.7.2