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

Commitfe0a1dc

Browse files
committed
Revert "Change SHA2 implementation based on OpenSSL to use EVP digest routines"
This reverts commite21cbb4, as the switch to EVP routines requires amore careful design where we would need to have at least our wrapperroutines return a status instead of issuing an error by themselves tolet the caller do the error handling. The memory handling was alsoincorrect and could cause leaks in the backend if a failure happened,requiring most likely a callback to do the necessary cleanup as the onlyclean way to be able to allocate an EVP context requires the use of anallocation within OpenSSL. The potential rework of the wrappers alsoimpacts the fallback implementation when not building with OpenSSL.Originally, prairiedog has reported a compilation failure, but afterdiscussion with Tom Lane this needs a better design.Discussion:https://postgr.es/m/20200928073330.GC2316@paquier.xyz
1 parent042d801 commitfe0a1dc

File tree

2 files changed

+19
-54
lines changed

2 files changed

+19
-54
lines changed

‎src/common/sha2_openssl.c

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,118 +20,83 @@
2020
#include"postgres_fe.h"
2121
#endif
2222

23-
#include"common/sha2.h"
24-
25-
#ifdefFRONTEND
26-
#include"common/logging.h"
27-
#else
28-
#include"miscadmin.h"
29-
#endif
23+
#include<openssl/sha.h>
3024

31-
#ifdefFRONTEND
32-
#definesha2_log_and_abort(...) \
33-
do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
34-
#else
35-
#definesha2_log_and_abort(...) elog(ERROR, __VA_ARGS__)
36-
#endif
37-
38-
staticvoid
39-
digest_init(EVP_MD_CTX**ctx,constEVP_MD*type)
40-
{
41-
*ctx=EVP_MD_CTX_create();
42-
if (*ctx==NULL)
43-
sha2_log_and_abort("could not create EVP digest context");
44-
if (EVP_DigestInit_ex(*ctx,type,NULL) <=0)
45-
sha2_log_and_abort("could not initialize EVP digest context");
46-
}
47-
48-
staticvoid
49-
digest_update(EVP_MD_CTX**ctx,constuint8*data,size_tlen)
50-
{
51-
if (EVP_DigestUpdate(*ctx,data,len) <=0)
52-
sha2_log_and_abort("could not update EVP digest context");
53-
}
25+
#include"common/sha2.h"
5426

55-
staticvoid
56-
digest_final(EVP_MD_CTX**ctx,uint8*dest)
57-
{
58-
if (EVP_DigestFinal_ex(*ctx,dest,0) <=0)
59-
sha2_log_and_abort("could not finalize EVP digest context");
60-
EVP_MD_CTX_destroy(*ctx);
61-
}
6227

6328
/* Interface routines for SHA-256 */
6429
void
6530
pg_sha256_init(pg_sha256_ctx*ctx)
6631
{
67-
digest_init(ctx,EVP_sha256());
32+
SHA256_Init((SHA256_CTX*)ctx);
6833
}
6934

7035
void
7136
pg_sha256_update(pg_sha256_ctx*ctx,constuint8*data,size_tlen)
7237
{
73-
digest_update(ctx,data,len);
38+
SHA256_Update((SHA256_CTX*)ctx,data,len);
7439
}
7540

7641
void
7742
pg_sha256_final(pg_sha256_ctx*ctx,uint8*dest)
7843
{
79-
digest_final(ctx,dest);
44+
SHA256_Final(dest, (SHA256_CTX*)ctx);
8045
}
8146

8247
/* Interface routines for SHA-512 */
8348
void
8449
pg_sha512_init(pg_sha512_ctx*ctx)
8550
{
86-
digest_init(ctx,EVP_sha512());
51+
SHA512_Init((SHA512_CTX*)ctx);
8752
}
8853

8954
void
9055
pg_sha512_update(pg_sha512_ctx*ctx,constuint8*data,size_tlen)
9156
{
92-
digest_update(ctx,data,len);
57+
SHA512_Update((SHA512_CTX*)ctx,data,len);
9358
}
9459

9560
void
9661
pg_sha512_final(pg_sha512_ctx*ctx,uint8*dest)
9762
{
98-
digest_final(ctx,dest);
63+
SHA512_Final(dest, (SHA512_CTX*)ctx);
9964
}
10065

10166
/* Interface routines for SHA-384 */
10267
void
10368
pg_sha384_init(pg_sha384_ctx*ctx)
10469
{
105-
digest_init(ctx,EVP_sha384());
70+
SHA384_Init((SHA512_CTX*)ctx);
10671
}
10772

10873
void
10974
pg_sha384_update(pg_sha384_ctx*ctx,constuint8*data,size_tlen)
11075
{
111-
digest_update(ctx,data,len);
76+
SHA384_Update((SHA512_CTX*)ctx,data,len);
11277
}
11378

11479
void
11580
pg_sha384_final(pg_sha384_ctx*ctx,uint8*dest)
11681
{
117-
digest_final(ctx,dest);
82+
SHA384_Final(dest, (SHA512_CTX*)ctx);
11883
}
11984

12085
/* Interface routines for SHA-224 */
12186
void
12287
pg_sha224_init(pg_sha224_ctx*ctx)
12388
{
124-
digest_init(ctx,EVP_sha224());
89+
SHA224_Init((SHA256_CTX*)ctx);
12590
}
12691

12792
void
12893
pg_sha224_update(pg_sha224_ctx*ctx,constuint8*data,size_tlen)
12994
{
130-
digest_update(ctx,data,len);
95+
SHA224_Update((SHA256_CTX*)ctx,data,len);
13196
}
13297

13398
void
13499
pg_sha224_final(pg_sha224_ctx*ctx,uint8*dest)
135100
{
136-
digest_final(ctx,dest);
101+
SHA224_Final(dest, (SHA256_CTX*)ctx);
137102
}

‎src/include/common/sha2.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#define_PG_SHA2_H_
5252

5353
#ifdefUSE_OPENSSL
54-
#include<openssl/evp.h>
54+
#include<openssl/sha.h>
5555
#endif
5656

5757
/*** SHA224/256/384/512 Various Length Definitions ***********************/
@@ -70,10 +70,10 @@
7070

7171
/* Context Structures for SHA224/256/384/512 */
7272
#ifdefUSE_OPENSSL
73-
typedefEVP_MD_CTX*pg_sha256_ctx;
74-
typedefEVP_MD_CTX*pg_sha512_ctx;
75-
typedefEVP_MD_CTX*pg_sha224_ctx;
76-
typedefEVP_MD_CTX*pg_sha384_ctx;
73+
typedefSHA256_CTXpg_sha256_ctx;
74+
typedefSHA512_CTXpg_sha512_ctx;
75+
typedefSHA256_CTXpg_sha224_ctx;
76+
typedefSHA512_CTXpg_sha384_ctx;
7777
#else
7878
typedefstructpg_sha256_ctx
7979
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp