• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Keith Holman - initial implementation and documentation
15  *******************************************************************************/
16 
17 #if !defined(SHA1_H)
18 #define SHA1_H
19 
20 #if defined(OPENSSL)
21 #include <openssl/sha.h>
22 
23 /** SHA-1 Digest Length */
24 #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
25 
26 #else /* if defined(OPENSSL) */
27 
28 #if defined(WIN32) || defined(WIN64)
29 #include <Windows.h>
30 #include <WinCrypt.h>
31 typedef struct SHA_CTX_S
32 {
33 	HCRYPTPROV hProv;
34 	HCRYPTHASH hHash;
35 } SHA_CTX;
36 #else /* if defined(WIN32) || defined(WIN64) */
37 
38 #include <stdint.h>
39 typedef struct SHA_CTX_S {
40 	uint32_t h[5];
41 	union {
42 		uint32_t w[16];
43 		uint8_t buffer[64];
44 	};
45 	unsigned int size;
46 	unsigned int total;
47 } SHA_CTX;
48 #endif /* else if defined(WIN32) || defined(WIN64) */
49 
50 #include <stddef.h>
51 
52 /** SHA-1 Digest Length (number of bytes in SHA1) */
53 #define SHA1_DIGEST_LENGTH (160/8)
54 
55 /**
56  * Initializes the SHA1 hashing algorithm
57  *
58  * @param[in,out]  ctx                 hashing context structure
59  *
60  * @see SHA1_Update
61  * @see SHA1_Final
62  */
63 int SHA1_Init(SHA_CTX *ctx);
64 
65 /**
66  * Updates a block to the SHA1 hash
67  *
68  * @param[in,out]  ctx                 hashing context structure
69  * @param[in]      data                block of data to hash
70  * @param[in]      len                 length of block to hash
71  *
72  * @see SHA1_Init
73  * @see SHA1_Final
74  */
75 int SHA1_Update(SHA_CTX *ctx, const void *data, size_t len);
76 
77 /**
78  * Produce final SHA1 hash
79  *
80  * @param[out]     md                  SHA1 hash produced (must be atleast
81  *                                     @p SHA1_DIGEST_LENGTH in length)
82  * @param[in,out]  ctx                 hashing context structure
83  *
84  * @see SHA1_Init
85  * @see SHA1_Final
86  */
87 int SHA1_Final(unsigned char *md, SHA_CTX *ctx);
88 
89 #endif /* if defined(OPENSSL) */
90 #endif /* SHA1_H */
91 
92