Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sha256.h
Go to the documentation of this file.
1 /* Declarations of functions and data types used for SHA256 and SHA224 sum
2  library functions.
3  Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software Foundation,
17  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 
19 /* This file is taken from coreutils-6.2 (lib/sha256.h) and adapted for dibbler
20  * by Michal Kowalczuk <michal@kowalczuk.eu> */
21 
22 #ifndef SHA256_H
23 # define SHA256_H 1
24 
25 # include <stdio.h>
26 # include <stdint.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define SHA224_BLOCKSIZE 64
33 #define SHA224_DIGESTSIZE 28
34 #define SHA256_BLOCKSIZE 64
35 #define SHA256_DIGESTSIZE 32
36 
37 /* Structure to save state of computation between the single steps. */
38 struct sha256_ctx
39 {
41 
45 };
46 
47 
48 /* Initialize structure containing state of computation. */
49 extern void sha256_init_ctx (struct sha256_ctx *ctx);
50 extern void sha224_init_ctx (struct sha256_ctx *ctx);
51 
52 /* Starting with the result of former calls of this function (or the
53  initialization function update the context for the next LEN bytes
54  starting at BUFFER.
55  It is necessary that LEN is a multiple of 64!!! */
56 extern void sha256_process_block (const void *buffer, size_t len,
57  struct sha256_ctx *ctx);
58 
59 /* Starting with the result of former calls of this function (or the
60  initialization function update the context for the next LEN bytes
61  starting at BUFFER.
62  It is NOT required that LEN is a multiple of 64. */
63 extern void sha256_process_bytes (const void *buffer, size_t len,
64  struct sha256_ctx *ctx);
65 
66 /* Process the remaining bytes in the buffer and put result from CTX
67  in first 32 (28) bytes following RESBUF. The result is always in little
68  endian byte order, so that a byte-wise output yields to the wanted
69  ASCII representation of the message digest.
70 
71  IMPORTANT: On some systems it is required that RESBUF be correctly
72  aligned for a 32 bits value. */
73 extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf);
74 extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf);
75 
76 
77 /* Put result from CTX in first 32 (28) bytes following RESBUF. The result is
78  always in little endian byte order, so that a byte-wise output yields
79  to the wanted ASCII representation of the message digest.
80 
81  IMPORTANT: On some systems it is required that RESBUF is correctly
82  aligned for a 32 bits value. */
83 extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf);
84 extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf);
85 
86 
87 /* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The
88  result is always in little endian byte order, so that a byte-wise
89  output yields to the wanted ASCII representation of the message
90  digest. */
91 extern void *sha256_buffer (const char *buffer, size_t len, void *resblock);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif
98