197447ea4SJohn-Mark Gurney /*- 297447ea4SJohn-Mark Gurney * Copyright 2005 Colin Percival 397447ea4SJohn-Mark Gurney * All rights reserved. 497447ea4SJohn-Mark Gurney * 597447ea4SJohn-Mark Gurney * Redistribution and use in source and binary forms, with or without 697447ea4SJohn-Mark Gurney * modification, are permitted provided that the following conditions 797447ea4SJohn-Mark Gurney * are met: 897447ea4SJohn-Mark Gurney * 1. Redistributions of source code must retain the above copyright 997447ea4SJohn-Mark Gurney * notice, this list of conditions and the following disclaimer. 1097447ea4SJohn-Mark Gurney * 2. Redistributions in binary form must reproduce the above copyright 1197447ea4SJohn-Mark Gurney * notice, this list of conditions and the following disclaimer in the 1297447ea4SJohn-Mark Gurney * documentation and/or other materials provided with the distribution. 1397447ea4SJohn-Mark Gurney * 1497447ea4SJohn-Mark Gurney * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1597447ea4SJohn-Mark Gurney * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1697447ea4SJohn-Mark Gurney * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1797447ea4SJohn-Mark Gurney * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1897447ea4SJohn-Mark Gurney * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1997447ea4SJohn-Mark Gurney * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2097447ea4SJohn-Mark Gurney * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2197447ea4SJohn-Mark Gurney * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2297447ea4SJohn-Mark Gurney * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2397447ea4SJohn-Mark Gurney * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2497447ea4SJohn-Mark Gurney * SUCH DAMAGE. 2597447ea4SJohn-Mark Gurney */ 2697447ea4SJohn-Mark Gurney 2797447ea4SJohn-Mark Gurney #ifndef _SHA256_H_ 2897447ea4SJohn-Mark Gurney #define _SHA256_H_ 2997447ea4SJohn-Mark Gurney 308083f14fSJohn-Mark Gurney #ifndef _KERNEL 3197447ea4SJohn-Mark Gurney #include <sys/types.h> 328083f14fSJohn-Mark Gurney #endif 3397447ea4SJohn-Mark Gurney 347a3f5d11SAllan Jude #define SHA256_BLOCK_LENGTH 64 357a3f5d11SAllan Jude #define SHA256_DIGEST_LENGTH 32 367a3f5d11SAllan Jude #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 377a3f5d11SAllan Jude 3897447ea4SJohn-Mark Gurney typedef struct SHA256Context { 3997447ea4SJohn-Mark Gurney uint32_t state[8]; 4097447ea4SJohn-Mark Gurney uint64_t count; 417a3f5d11SAllan Jude uint8_t buf[SHA256_BLOCK_LENGTH]; 4297447ea4SJohn-Mark Gurney } SHA256_CTX; 4397447ea4SJohn-Mark Gurney 4497447ea4SJohn-Mark Gurney __BEGIN_DECLS 452ff9c4f9SJohn-Mark Gurney 462ff9c4f9SJohn-Mark Gurney /* Ensure libmd symbols do not clash with libcrypto */ 472ff9c4f9SJohn-Mark Gurney 482ff9c4f9SJohn-Mark Gurney #ifndef SHA256_Init 492ff9c4f9SJohn-Mark Gurney #define SHA256_Init _libmd_SHA256_Init 502ff9c4f9SJohn-Mark Gurney #endif 512ff9c4f9SJohn-Mark Gurney #ifndef SHA256_Update 522ff9c4f9SJohn-Mark Gurney #define SHA256_Update _libmd_SHA256_Update 532ff9c4f9SJohn-Mark Gurney #endif 542ff9c4f9SJohn-Mark Gurney #ifndef SHA256_Final 552ff9c4f9SJohn-Mark Gurney #define SHA256_Final _libmd_SHA256_Final 562ff9c4f9SJohn-Mark Gurney #endif 572ff9c4f9SJohn-Mark Gurney #ifndef SHA256_End 582ff9c4f9SJohn-Mark Gurney #define SHA256_End _libmd_SHA256_End 592ff9c4f9SJohn-Mark Gurney #endif 60de13c242SEd Maste #ifndef SHA256_Fd 61de13c242SEd Maste #define SHA256_Fd _libmd_SHA256_Fd 62de13c242SEd Maste #endif 63de13c242SEd Maste #ifndef SHA256_FdChunk 64de13c242SEd Maste #define SHA256_FdChunk _libmd_SHA256_FdChunk 65de13c242SEd Maste #endif 662ff9c4f9SJohn-Mark Gurney #ifndef SHA256_File 672ff9c4f9SJohn-Mark Gurney #define SHA256_File _libmd_SHA256_File 682ff9c4f9SJohn-Mark Gurney #endif 692ff9c4f9SJohn-Mark Gurney #ifndef SHA256_FileChunk 702ff9c4f9SJohn-Mark Gurney #define SHA256_FileChunk _libmd_SHA256_FileChunk 712ff9c4f9SJohn-Mark Gurney #endif 722ff9c4f9SJohn-Mark Gurney #ifndef SHA256_Data 732ff9c4f9SJohn-Mark Gurney #define SHA256_Data _libmd_SHA256_Data 742ff9c4f9SJohn-Mark Gurney #endif 75*c02bc0aaSKyle Evans #ifndef SHA256_Transform 76*c02bc0aaSKyle Evans #define SHA256_Transform _libmd_SHA256_Transform 77*c02bc0aaSKyle Evans #endif 782ff9c4f9SJohn-Mark Gurney 7997447ea4SJohn-Mark Gurney void SHA256_Init(SHA256_CTX *); 8097447ea4SJohn-Mark Gurney void SHA256_Update(SHA256_CTX *, const void *, size_t); 818254c3c5SAlan Somers void SHA256_Final(unsigned char [__min_size(SHA256_DIGEST_LENGTH)], 828254c3c5SAlan Somers SHA256_CTX *); 837a3f5d11SAllan Jude #ifndef _KERNEL 8497447ea4SJohn-Mark Gurney char *SHA256_End(SHA256_CTX *, char *); 858083f14fSJohn-Mark Gurney char *SHA256_Data(const void *, unsigned int, char *); 86de13c242SEd Maste char *SHA256_Fd(int, char *); 87de13c242SEd Maste char *SHA256_FdChunk(int, char *, off_t, off_t); 8897447ea4SJohn-Mark Gurney char *SHA256_File(const char *, char *); 8997447ea4SJohn-Mark Gurney char *SHA256_FileChunk(const char *, char *, off_t, off_t); 908083f14fSJohn-Mark Gurney #endif 9197447ea4SJohn-Mark Gurney __END_DECLS 9297447ea4SJohn-Mark Gurney 9397447ea4SJohn-Mark Gurney #endif /* !_SHA256_H_ */ 94