PostgreSQL Source Code  git master
sha2_openssl.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * sha2_openssl.c
4  * Set of wrapper routines on top of OpenSSL to support SHA-224
5  * SHA-256, SHA-384 and SHA-512 functions.
6  *
7  * This should only be used if code is compiled with OpenSSL support.
8  *
9  * Portions Copyright (c) 2016-2020, PostgreSQL Global Development Group
10  *
11  * IDENTIFICATION
12  * src/common/sha2_openssl.c
13  *
14  *-------------------------------------------------------------------------
15  */
16 
17 #ifndef FRONTEND
18 #include "postgres.h"
19 #else
20 #include "postgres_fe.h"
21 #endif
22 
23 #include <openssl/sha.h>
24 
25 #include "common/sha2.h"
26 
27 
28 /* Interface routines for SHA-256 */
29 void
31 {
32  SHA256_Init((SHA256_CTX *) ctx);
33 }
34 
35 void
36 pg_sha256_update(pg_sha256_ctx *ctx, const uint8 *data, size_t len)
37 {
38  SHA256_Update((SHA256_CTX *) ctx, data, len);
39 }
40 
41 void
43 {
44  SHA256_Final(dest, (SHA256_CTX *) ctx);
45 }
46 
47 /* Interface routines for SHA-512 */
48 void
50 {
51  SHA512_Init((SHA512_CTX *) ctx);
52 }
53 
54 void
55 pg_sha512_update(pg_sha512_ctx *ctx, const uint8 *data, size_t len)
56 {
57  SHA512_Update((SHA512_CTX *) ctx, data, len);
58 }
59 
60 void
62 {
63  SHA512_Final(dest, (SHA512_CTX *) ctx);
64 }
65 
66 /* Interface routines for SHA-384 */
67 void
69 {
70  SHA384_Init((SHA512_CTX *) ctx);
71 }
72 
73 void
74 pg_sha384_update(pg_sha384_ctx *ctx, const uint8 *data, size_t len)
75 {
76  SHA384_Update((SHA512_CTX *) ctx, data, len);
77 }
78 
79 void
81 {
82  SHA384_Final(dest, (SHA512_CTX *) ctx);
83 }
84 
85 /* Interface routines for SHA-224 */
86 void
88 {
89  SHA224_Init((SHA256_CTX *) ctx);
90 }
91 
92 void
93 pg_sha224_update(pg_sha224_ctx *ctx, const uint8 *data, size_t len)
94 {
95  SHA224_Update((SHA256_CTX *) ctx, data, len);
96 }
97 
98 void
100 {
101  SHA224_Final(dest, (SHA256_CTX *) ctx);
102 }
void pg_sha384_init(pg_sha384_ctx *ctx)
Definition: sha2_openssl.c:68
unsigned char uint8
Definition: c.h:365
void pg_sha384_final(pg_sha384_ctx *ctx, uint8 *dest)
Definition: sha2_openssl.c:80
void pg_sha256_update(pg_sha256_ctx *ctx, const uint8 *data, size_t len)
Definition: sha2_openssl.c:36
void pg_sha224_init(pg_sha224_ctx *ctx)
Definition: sha2_openssl.c:87
void pg_sha224_update(pg_sha224_ctx *ctx, const uint8 *data, size_t len)
Definition: sha2_openssl.c:93
void pg_sha512_init(pg_sha512_ctx *ctx)
Definition: sha2_openssl.c:49
void pg_sha256_final(pg_sha256_ctx *ctx, uint8 *dest)
Definition: sha2_openssl.c:42
void pg_sha384_update(pg_sha384_ctx *ctx, const uint8 *data, size_t len)
Definition: sha2_openssl.c:74
void pg_sha224_final(pg_sha224_ctx *ctx, uint8 *dest)
Definition: sha2_openssl.c:99
void pg_sha512_update(pg_sha512_ctx *ctx, const uint8 *data, size_t len)
Definition: sha2_openssl.c:55
void pg_sha256_init(pg_sha256_ctx *ctx)
Definition: sha2_openssl.c:30
void pg_sha512_final(pg_sha512_ctx *ctx, uint8 *dest)
Definition: sha2_openssl.c:61