Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit273c458

Browse files
committed
Refactor SHA2 functions and move them to src/common/.
This way both frontend and backends can use them. The functions are takenfrom pgcrypto, which now fetches the source files it needs fromsrc/common/.A new interface is designed for the SHA2 functions, which allow linkingto either OpenSSL or the in-core stuff taken from KAME as needed.Michael Paquier, reviewed by Robert Haas.Discussion:https://www.postgresql.org/message-id/CAB7nPqTGKuTM5jiZriHrNaQeVqp5e_iT3X4BFLWY_HyHxLvySQ%40mail.gmail.com
1 parent330b84d commit273c458

File tree

9 files changed

+385
-227
lines changed

9 files changed

+385
-227
lines changed

‎contrib/pgcrypto/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Source file copied from src/common
2+
/sha2.c
3+
/sha2_openssl.c
4+
15
# Generated subdirectories
26
/log/
37
/results/

‎contrib/pgcrypto/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ INT_SRCS = md5.c sha1.c sha2.c internal.c internal-sha2.c blf.c rijndael.c \
44
pgp-mpi-internal.c imath.c
55
INT_TESTS = sha2
66

7-
OSSL_SRCS = openssl.c pgp-mpi-openssl.c
7+
OSSL_SRCS = openssl.c pgp-mpi-openssl.c sha2_openssl.c
88
OSSL_TESTS = sha2 des 3des cast5
99

1010
ZLIB_TST = pgp-compression
@@ -59,6 +59,13 @@ SHLIB_LINK += $(filter -leay32, $(LIBS))
5959
SHLIB_LINK += -lws2_32
6060
endif
6161

62+
# Compiling pgcrypto with those two raw files is necessary as long
63+
# as none of their routines are used by the backend code. Note doing
64+
# so can either result in library loading failures or linking resolution
65+
# failures at compilation depending on the environment used.
66+
sha2.csha2_openssl.c:% :$(top_srcdir)/src/common/%
67+
rm -f$@&&$(LN_S)$<.
68+
6269
rijndael.o: rijndael.tbl
6370

6471
rijndael.tbl:

‎contrib/pgcrypto/internal-sha2.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
#include<time.h>
3535

36+
#include"common/sha2.h"
3637
#include"px.h"
37-
#include"sha2.h"
3838

3939
voidinit_sha224(PX_MD*h);
4040
voidinit_sha256(PX_MD*h);
@@ -46,43 +46,43 @@ voidinit_sha512(PX_MD *h);
4646
staticunsigned
4747
int_sha224_len(PX_MD*h)
4848
{
49-
returnSHA224_DIGEST_LENGTH;
49+
returnPG_SHA224_DIGEST_LENGTH;
5050
}
5151

5252
staticunsigned
5353
int_sha224_block_len(PX_MD*h)
5454
{
55-
returnSHA224_BLOCK_LENGTH;
55+
returnPG_SHA224_BLOCK_LENGTH;
5656
}
5757

5858
staticvoid
5959
int_sha224_update(PX_MD*h,constuint8*data,unsigneddlen)
6060
{
61-
SHA224_CTX*ctx= (SHA224_CTX*)h->p.ptr;
61+
pg_sha224_ctx*ctx= (pg_sha224_ctx*)h->p.ptr;
6262

63-
SHA224_Update(ctx,data,dlen);
63+
pg_sha224_update(ctx,data,dlen);
6464
}
6565

6666
staticvoid
6767
int_sha224_reset(PX_MD*h)
6868
{
69-
SHA224_CTX*ctx= (SHA224_CTX*)h->p.ptr;
69+
pg_sha224_ctx*ctx= (pg_sha224_ctx*)h->p.ptr;
7070

71-
SHA224_Init(ctx);
71+
pg_sha224_init(ctx);
7272
}
7373

7474
staticvoid
7575
int_sha224_finish(PX_MD*h,uint8*dst)
7676
{
77-
SHA224_CTX*ctx= (SHA224_CTX*)h->p.ptr;
77+
pg_sha224_ctx*ctx= (pg_sha224_ctx*)h->p.ptr;
7878

79-
SHA224_Final(dst,ctx);
79+
pg_sha224_final(ctx,dst);
8080
}
8181

8282
staticvoid
8383
int_sha224_free(PX_MD*h)
8484
{
85-
SHA224_CTX*ctx= (SHA224_CTX*)h->p.ptr;
85+
pg_sha224_ctx*ctx= (pg_sha224_ctx*)h->p.ptr;
8686

8787
px_memset(ctx,0,sizeof(*ctx));
8888
px_free(ctx);
@@ -94,43 +94,43 @@ int_sha224_free(PX_MD *h)
9494
staticunsigned
9595
int_sha256_len(PX_MD*h)
9696
{
97-
returnSHA256_DIGEST_LENGTH;
97+
returnPG_SHA256_DIGEST_LENGTH;
9898
}
9999

100100
staticunsigned
101101
int_sha256_block_len(PX_MD*h)
102102
{
103-
returnSHA256_BLOCK_LENGTH;
103+
returnPG_SHA256_BLOCK_LENGTH;
104104
}
105105

106106
staticvoid
107107
int_sha256_update(PX_MD*h,constuint8*data,unsigneddlen)
108108
{
109-
SHA256_CTX*ctx= (SHA256_CTX*)h->p.ptr;
109+
pg_sha256_ctx*ctx= (pg_sha256_ctx*)h->p.ptr;
110110

111-
SHA256_Update(ctx,data,dlen);
111+
pg_sha256_update(ctx,data,dlen);
112112
}
113113

114114
staticvoid
115115
int_sha256_reset(PX_MD*h)
116116
{
117-
SHA256_CTX*ctx= (SHA256_CTX*)h->p.ptr;
117+
pg_sha256_ctx*ctx= (pg_sha256_ctx*)h->p.ptr;
118118

119-
SHA256_Init(ctx);
119+
pg_sha256_init(ctx);
120120
}
121121

122122
staticvoid
123123
int_sha256_finish(PX_MD*h,uint8*dst)
124124
{
125-
SHA256_CTX*ctx= (SHA256_CTX*)h->p.ptr;
125+
pg_sha256_ctx*ctx= (pg_sha256_ctx*)h->p.ptr;
126126

127-
SHA256_Final(dst,ctx);
127+
pg_sha256_final(ctx,dst);
128128
}
129129

130130
staticvoid
131131
int_sha256_free(PX_MD*h)
132132
{
133-
SHA256_CTX*ctx= (SHA256_CTX*)h->p.ptr;
133+
pg_sha256_ctx*ctx= (pg_sha256_ctx*)h->p.ptr;
134134

135135
px_memset(ctx,0,sizeof(*ctx));
136136
px_free(ctx);
@@ -142,43 +142,43 @@ int_sha256_free(PX_MD *h)
142142
staticunsigned
143143
int_sha384_len(PX_MD*h)
144144
{
145-
returnSHA384_DIGEST_LENGTH;
145+
returnPG_SHA384_DIGEST_LENGTH;
146146
}
147147

148148
staticunsigned
149149
int_sha384_block_len(PX_MD*h)
150150
{
151-
returnSHA384_BLOCK_LENGTH;
151+
returnPG_SHA384_BLOCK_LENGTH;
152152
}
153153

154154
staticvoid
155155
int_sha384_update(PX_MD*h,constuint8*data,unsigneddlen)
156156
{
157-
SHA384_CTX*ctx= (SHA384_CTX*)h->p.ptr;
157+
pg_sha384_ctx*ctx= (pg_sha384_ctx*)h->p.ptr;
158158

159-
SHA384_Update(ctx,data,dlen);
159+
pg_sha384_update(ctx,data,dlen);
160160
}
161161

162162
staticvoid
163163
int_sha384_reset(PX_MD*h)
164164
{
165-
SHA384_CTX*ctx= (SHA384_CTX*)h->p.ptr;
165+
pg_sha384_ctx*ctx= (pg_sha384_ctx*)h->p.ptr;
166166

167-
SHA384_Init(ctx);
167+
pg_sha384_init(ctx);
168168
}
169169

170170
staticvoid
171171
int_sha384_finish(PX_MD*h,uint8*dst)
172172
{
173-
SHA384_CTX*ctx= (SHA384_CTX*)h->p.ptr;
173+
pg_sha384_ctx*ctx= (pg_sha384_ctx*)h->p.ptr;
174174

175-
SHA384_Final(dst,ctx);
175+
pg_sha384_final(ctx,dst);
176176
}
177177

178178
staticvoid
179179
int_sha384_free(PX_MD*h)
180180
{
181-
SHA384_CTX*ctx= (SHA384_CTX*)h->p.ptr;
181+
pg_sha384_ctx*ctx= (pg_sha384_ctx*)h->p.ptr;
182182

183183
px_memset(ctx,0,sizeof(*ctx));
184184
px_free(ctx);
@@ -190,43 +190,43 @@ int_sha384_free(PX_MD *h)
190190
staticunsigned
191191
int_sha512_len(PX_MD*h)
192192
{
193-
returnSHA512_DIGEST_LENGTH;
193+
returnPG_SHA512_DIGEST_LENGTH;
194194
}
195195

196196
staticunsigned
197197
int_sha512_block_len(PX_MD*h)
198198
{
199-
returnSHA512_BLOCK_LENGTH;
199+
returnPG_SHA512_BLOCK_LENGTH;
200200
}
201201

202202
staticvoid
203203
int_sha512_update(PX_MD*h,constuint8*data,unsigneddlen)
204204
{
205-
SHA512_CTX*ctx= (SHA512_CTX*)h->p.ptr;
205+
pg_sha512_ctx*ctx= (pg_sha512_ctx*)h->p.ptr;
206206

207-
SHA512_Update(ctx,data,dlen);
207+
pg_sha512_update(ctx,data,dlen);
208208
}
209209

210210
staticvoid
211211
int_sha512_reset(PX_MD*h)
212212
{
213-
SHA512_CTX*ctx= (SHA512_CTX*)h->p.ptr;
213+
pg_sha512_ctx*ctx= (pg_sha512_ctx*)h->p.ptr;
214214

215-
SHA512_Init(ctx);
215+
pg_sha512_init(ctx);
216216
}
217217

218218
staticvoid
219219
int_sha512_finish(PX_MD*h,uint8*dst)
220220
{
221-
SHA512_CTX*ctx= (SHA512_CTX*)h->p.ptr;
221+
pg_sha512_ctx*ctx= (pg_sha512_ctx*)h->p.ptr;
222222

223-
SHA512_Final(dst,ctx);
223+
pg_sha512_final(ctx,dst);
224224
}
225225

226226
staticvoid
227227
int_sha512_free(PX_MD*h)
228228
{
229-
SHA512_CTX*ctx= (SHA512_CTX*)h->p.ptr;
229+
pg_sha512_ctx*ctx= (pg_sha512_ctx*)h->p.ptr;
230230

231231
px_memset(ctx,0,sizeof(*ctx));
232232
px_free(ctx);
@@ -238,7 +238,7 @@ int_sha512_free(PX_MD *h)
238238
void
239239
init_sha224(PX_MD*md)
240240
{
241-
SHA224_CTX*ctx;
241+
pg_sha224_ctx*ctx;
242242

243243
ctx=px_alloc(sizeof(*ctx));
244244
memset(ctx,0,sizeof(*ctx));
@@ -258,7 +258,7 @@ init_sha224(PX_MD *md)
258258
void
259259
init_sha256(PX_MD*md)
260260
{
261-
SHA256_CTX*ctx;
261+
pg_sha256_ctx*ctx;
262262

263263
ctx=px_alloc(sizeof(*ctx));
264264
memset(ctx,0,sizeof(*ctx));
@@ -278,7 +278,7 @@ init_sha256(PX_MD *md)
278278
void
279279
init_sha384(PX_MD*md)
280280
{
281-
SHA384_CTX*ctx;
281+
pg_sha384_ctx*ctx;
282282

283283
ctx=px_alloc(sizeof(*ctx));
284284
memset(ctx,0,sizeof(*ctx));
@@ -298,7 +298,7 @@ init_sha384(PX_MD *md)
298298
void
299299
init_sha512(PX_MD*md)
300300
{
301-
SHA512_CTX*ctx;
301+
pg_sha512_ctx*ctx;
302302

303303
ctx=px_alloc(sizeof(*ctx));
304304
memset(ctx,0,sizeof(*ctx));

‎contrib/pgcrypto/sha2.h

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp