1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _NANOHUB_SHA2_H_ 18 #define _NANOHUB_SHA2_H_ 19 20 //this is neither the fastest nor the smallest. but it is simple and matches the spec. cool. 21 22 #include <stdint.h> 23 24 #define SHA2_BLOCK_SIZE 64U //in bytes 25 #define SHA2_WORDS_STATE_SIZE 64U //in words 26 27 #define SHA2_HASH_SIZE 32U //in bytes 28 #define SHA2_HASH_WORDS 8U //in words 29 30 struct Sha2state { 31 uint32_t h[8]; 32 uint64_t msgLen; 33 union { 34 uint32_t w[SHA2_WORDS_STATE_SIZE]; 35 uint8_t b[SHA2_BLOCK_SIZE]; 36 }; 37 uint8_t bufBytesUsed; 38 }; 39 40 void sha2init(struct Sha2state *state); 41 void sha2processBytes(struct Sha2state *state, const void *bytes, uint32_t numBytes); 42 const uint32_t* sha2finish(struct Sha2state *state); //returned hash pointer is only valid as long as "state" is! 43 44 45 46 47 48 #endif // _NANOHUB_SHA2_H_ 49 50