xref: /PHP-7.3/ext/hash/php_hash_sha.h (revision 8d3f8ca1)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | SHA1 Author: Stefan Esser <sesser@php.net>                           |
16    | SHA256 Author: Sara Golemon <pollita@php.net>                        |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef PHP_HASH_SHA_H
21 #define PHP_HASH_SHA_H
22 
23 /* When SHA is removed from Core,
24 	the ext/standard/sha1.c file can be removed
25 	and the ext/standard/sha1.h file can be reduced to:
26 		#define PHP_HASH_SHA1_NOT_IN_CORE
27 		#include "ext/hash/php_hash_sha.h"
28 	Don't forget to remove sha1() and sha1_file() from basic_functions.c
29  */
30 #include "ext/standard/sha1.h"
31 #include "ext/standard/basic_functions.h"
32 
33 #ifdef PHP_HASH_SHA1_NOT_IN_CORE
34 
35 /* SHA1 context. */
36 typedef struct {
37 	uint32_t state[5];		/* state (ABCD) */
38 	uint32_t count[2];		/* number of bits, modulo 2^64 */
39 	unsigned char buffer[64];	/* input buffer */
40 } PHP_SHA1_CTX;
41 
42 PHP_HASH_API void PHP_SHA1Init(PHP_SHA1_CTX *);
43 PHP_HASH_API void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, unsigned int);
44 PHP_HASH_API void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *);
45 
46 PHP_FUNCTION(sha1);
47 PHP_FUNCTION(sha1_file);
48 
49 #endif /* PHP_HASH_SHA1_NOT_IN_CORE */
50 
51 /* SHA224 context. */
52 typedef struct {
53 	uint32_t state[8];		/* state */
54 	uint32_t count[2];		/* number of bits, modulo 2^64 */
55 	unsigned char buffer[64];	/* input buffer */
56 } PHP_SHA224_CTX;
57 
58 PHP_HASH_API void PHP_SHA224Init(PHP_SHA224_CTX *);
59 PHP_HASH_API void PHP_SHA224Update(PHP_SHA224_CTX *, const unsigned char *, unsigned int);
60 PHP_HASH_API void PHP_SHA224Final(unsigned char[28], PHP_SHA224_CTX *);
61 
62 /* SHA256 context. */
63 typedef struct {
64 	uint32_t state[8];		/* state */
65 	uint32_t count[2];		/* number of bits, modulo 2^64 */
66 	unsigned char buffer[64];	/* input buffer */
67 } PHP_SHA256_CTX;
68 
69 PHP_HASH_API void PHP_SHA256Init(PHP_SHA256_CTX *);
70 PHP_HASH_API void PHP_SHA256Update(PHP_SHA256_CTX *, const unsigned char *, unsigned int);
71 PHP_HASH_API void PHP_SHA256Final(unsigned char[32], PHP_SHA256_CTX *);
72 
73 /* SHA384 context */
74 typedef struct {
75 	uint64_t state[8];	/* state */
76 	uint64_t count[2];	/* number of bits, modulo 2^128 */
77 	unsigned char buffer[128];	/* input buffer */
78 } PHP_SHA384_CTX;
79 
80 PHP_HASH_API void PHP_SHA384Init(PHP_SHA384_CTX *);
81 PHP_HASH_API void PHP_SHA384Update(PHP_SHA384_CTX *, const unsigned char *, unsigned int);
82 PHP_HASH_API void PHP_SHA384Final(unsigned char[48], PHP_SHA384_CTX *);
83 
84 /* SHA512 context */
85 typedef struct {
86 	uint64_t state[8];	/* state */
87 	uint64_t count[2];	/* number of bits, modulo 2^128 */
88 	unsigned char buffer[128];	/* input buffer */
89 } PHP_SHA512_CTX;
90 
91 PHP_HASH_API void PHP_SHA512Init(PHP_SHA512_CTX *);
92 PHP_HASH_API void PHP_SHA512Update(PHP_SHA512_CTX *, const unsigned char *, unsigned int);
93 PHP_HASH_API void PHP_SHA512Final(unsigned char[64], PHP_SHA512_CTX *);
94 
95 PHP_HASH_API void PHP_SHA512_256Init(PHP_SHA512_CTX *);
96 #define PHP_SHA512_256Update PHP_SHA512Update
97 PHP_HASH_API void PHP_SHA512_256Final(unsigned char[32], PHP_SHA512_CTX *);
98 
99 PHP_HASH_API void PHP_SHA512_224Init(PHP_SHA512_CTX *);
100 #define PHP_SHA512_224Update PHP_SHA512Update
101 PHP_HASH_API void PHP_SHA512_224Final(unsigned char[28], PHP_SHA512_CTX *);
102 
103 #endif /* PHP_HASH_SHA_H */
104