Fri, 30 May 2025 12:07:10 +0200
add common crypto hashing implementation for macOS
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2025 Olaf Wintermann. All rights reserved. |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "hashing.h" |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <stdlib.h> |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
33 | WS_SHA1_CTX* ws_sha1_create(void) { |
| 587 | 34 | WS_SHA1_CTX *ctx = malloc(sizeof(WS_SHA1_CTX)); |
| 35 | if(!ctx) { | |
| 36 | return NULL; | |
| 37 | } | |
| 38 | if(ws_sha1_init(ctx)) { | |
| 39 | free(ctx); | |
| 40 | return NULL; | |
| 41 | } | |
| 42 | return ctx; | |
| 43 | } | |
| 44 | ||
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
45 | WS_SHA256_CTX* ws_sha256_create(void) { |
| 587 | 46 | WS_SHA256_CTX *ctx = malloc(sizeof(WS_SHA256_CTX)); |
| 47 | if(!ctx) { | |
| 48 | return NULL; | |
| 49 | } | |
| 50 | if(ws_sha256_init(ctx)) { | |
| 51 | free(ctx); | |
| 52 | return NULL; | |
| 53 | } | |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | return ctx; |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
57 | WS_SHA1_CTX* ws_sha512_create(void) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
58 | WS_SHA512_CTX *ctx = malloc(sizeof(WS_SHA512_CTX)); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
59 | if(!ctx) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
60 | return NULL; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
61 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
62 | if(ws_sha512_init(ctx)) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
63 | free(ctx); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
64 | return NULL; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
65 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
66 | return ctx; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
67 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
68 | |
|
594
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
69 | #ifdef WS_USE_OPENSSL |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
70 | |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | #if OPENSSL_VERSION_NUMBER < 0x30000000L |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
| 587 | 73 | void ws_sha1_init(WS_SHA1_CTX *ctx) { |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | SHA256_Init(ctx); |
| 587 | 75 | return 0; |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | |
| 587 | 78 | void ws_sha1_update(WS_SHA1_CTX *ctx, const void *data, size_t length) { |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | SHA256_Update(ctx, data, length); |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
| 587 | 82 | void ws_sha1_final(char *md, WS_SHA1_CTX *ctx) { |
| 83 | SHA_Final(md, ctx); | |
| 84 | } | |
| 85 | ||
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
86 | void ws_sha256_init(WS_SHA256_CTX *ctx) { |
| 587 | 87 | SHA_Init(ctx); |
| 88 | return 0; | |
| 89 | } | |
| 90 | ||
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
91 | void ws_sha256_update(WS_SHA256_CTX *ctx, const void *data, size_t length) { |
| 587 | 92 | SHA_Update(ctx, data, length); |
| 93 | } | |
| 94 | ||
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
95 | void ws_sha256_final(char *md, WS_SHA256_CTX *ctx) { |
| 587 | 96 | SHA_Final(md, ctx); |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | |
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
99 | void ws_sha512_init(WS_SHA512_CTX *ctx) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
100 | SHA512_Init(ctx); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
101 | return 0; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
102 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
103 | |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
104 | void ws_sha256_update(WS_SHA512_CTX *ctx, const void *data, size_t length) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
105 | SHA512_Update(ctx, data, length); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
106 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
107 | |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
108 | void ws_sha256_final(char *md, WS_SHA512_CTX *ctx) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
109 | SHA512_Final(md, ctx); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
110 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
111 | |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | #else |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
| 587 | 114 | int ws_sha1_init(WS_SHA256_CTX *ctx) { |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); |
| 587 | 116 | if(!mdctx) { |
| 117 | return 1; | |
| 118 | } | |
| 119 | EVP_DigestInit_ex(mdctx, EVP_sha1(), NULL); | |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | *ctx = mdctx; |
| 587 | 121 | return 0; |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
| 587 | 124 | void ws_sha1_update(WS_SHA256_CTX *ctx, const char *data, size_t length) { |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | EVP_DigestUpdate(*ctx, data, length); |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
| 587 | 128 | void ws_sha1_final(WS_SHA256_CTX *ctx, unsigned char *md) { |
| 129 | EVP_DigestFinal(*ctx, md, NULL); | |
| 130 | } | |
| 131 | ||
| 132 | int ws_sha256_init(WS_SHA256_CTX *ctx) { | |
| 133 | EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); | |
| 134 | if(!mdctx) { | |
| 135 | return 1; | |
| 136 | } | |
| 137 | EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL); | |
| 138 | *ctx = mdctx; | |
| 139 | return 0; | |
| 140 | } | |
| 141 | ||
| 142 | void ws_sha256_update(WS_SHA256_CTX *ctx, const char *data, size_t length) { | |
| 143 | EVP_DigestUpdate(*ctx, data, length); | |
| 144 | } | |
| 145 | ||
| 146 | void ws_sha256_final(WS_SHA256_CTX *ctx, unsigned char *md) { | |
|
586
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | EVP_DigestFinal(*ctx, md, NULL); |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | } |
|
9861e8ceaf96
add wrapper for openssl hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
|
589
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
150 | int ws_sha512_init(WS_SHA512_CTX *ctx) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
151 | EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
152 | if(!mdctx) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
153 | return 1; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
154 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
155 | EVP_DigestInit_ex(mdctx, EVP_sha512(), NULL); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
156 | *ctx = mdctx; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
157 | return 0; |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
158 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
159 | |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
160 | void ws_sha512_update(WS_SHA256_CTX *ctx, const char *data, size_t length) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
161 | EVP_DigestUpdate(*ctx, data, length); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
162 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
163 | |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
164 | void ws_sha512_final(WS_SHA256_CTX *ctx, unsigned char *md) { |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
165 | EVP_DigestFinal(*ctx, md, NULL); |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
166 | } |
|
70ad04769cbf
add sha512 hashing functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
587
diff
changeset
|
167 | |
|
594
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
168 | #endif // OPENSSL_VERSION_NUMBER < 0x30000000L |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
169 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
170 | #endif // WS_USE_OPENSSL |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
171 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
172 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
173 | #ifdef WS_USE_CRYPTO_COMMON |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
174 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
175 | int ws_sha1_init(WS_SHA1_CTX *ctx) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
176 | CC_SHA1_Init(ctx); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
177 | return 0; |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
178 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
179 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
180 | void ws_sha1_update(WS_SHA1_CTX *ctx, const char *data, size_t len) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
181 | CC_SHA1_Update(ctx, data, len); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
182 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
183 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
184 | void ws_sha1_final(WS_SHA1_CTX *ctx, unsigned char *buf) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
185 | CC_SHA1_Final(buf, ctx); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
186 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
187 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
188 | int ws_sha256_init(WS_SHA256_CTX *ctx) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
189 | CC_SHA256_Init(ctx); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
190 | return 0; |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
191 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
192 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
193 | void ws_sha256_update(WS_SHA256_CTX *ctx, const char *data, size_t len) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
194 | CC_SHA256_Update(ctx, data, len); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
195 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
196 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
197 | void ws_sha256_final(WS_SHA256_CTX *ctx, unsigned char *buf) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
198 | CC_SHA256_Final(buf, ctx); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
199 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
200 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
201 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
202 | int ws_sha512_init(WS_SHA512_CTX *ctx) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
203 | CC_SHA512_Init(ctx); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
204 | return 0; |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
205 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
206 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
207 | void ws_sha512_update(WS_SHA512_CTX *ctx, const char *data, size_t len) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
208 | CC_SHA512_Update(ctx, data, len); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
209 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
210 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
211 | void ws_sha512_final(WS_SHA512_CTX *ctx, unsigned char *buf) { |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
212 | CC_SHA512_Final(buf, ctx); |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
213 | } |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
214 | |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
215 | #endif // WS_USE_CRYPTO_COMMON |
|
36a46311e0f6
add common crypto hashing implementation for macOS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
589
diff
changeset
|
216 |