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

Commit9b58495

Browse files
committed
Improve some code around cryptohash functions
This adjusts some code related to recent changes for cryptohashfunctions:- Add a variable in md5.h to track down the size of a computed result,moved from pgcrypto. Note that pg_md5_hash() assumed a result of thissize already.- Call explicit_bzero() on the hashed data when freeing the context forfallback implementations. For MD5, particularly, it would be annoyingto leave some non-zeroed data around.- Clean up some code related to recent changes of uuid-ossp. .gitignorestill included md5.c and a comment was incorrect.Discussion:https://postgr.es/m/X9HXKTgrvJvYO7Oh@paquier.xyz
1 parentdf9274a commit9b58495

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

‎contrib/pgcrypto/internal.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
#include"common/cryptohash.h"
4242
#include"common/md5.h"
4343

44-
#ifndefMD5_DIGEST_LENGTH
45-
#defineMD5_DIGEST_LENGTH 16
46-
#endif
47-
4844
#ifndefSHA1_DIGEST_LENGTH
4945
#ifdefSHA1_RESULTLEN
5046
#defineSHA1_DIGEST_LENGTH SHA1_RESULTLEN

‎contrib/uuid-ossp/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/md5.c
21
/sha1.c
32
# Generated subdirectories
43
/log/

‎contrib/uuid-ossp/uuid-ossp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#undef uuid_hash
4242

4343
/*
44-
* Some BSD variants offermd5 andsha1implementations but Linux does not,
45-
*so we usea copy of the ones from pgcrypto. Not needed with OSSP, though.
44+
* Some BSD variants offer sha1implementation but Linux does not, so we use
45+
* a copy from pgcrypto. Not needed with OSSP, though.
4646
*/
4747
#ifndefHAVE_UUID_OSSP
4848
#include"sha1.h"

‎src/common/cryptohash.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ pg_cryptohash_free(pg_cryptohash_ctx *ctx)
197197
{
198198
if (ctx==NULL)
199199
return;
200+
201+
switch (ctx->type)
202+
{
203+
casePG_MD5:
204+
explicit_bzero(ctx->data,sizeof(pg_md5_ctx));
205+
break;
206+
casePG_SHA224:
207+
explicit_bzero(ctx->data,sizeof(pg_sha224_ctx));
208+
break;
209+
casePG_SHA256:
210+
explicit_bzero(ctx->data,sizeof(pg_sha256_ctx));
211+
break;
212+
casePG_SHA384:
213+
explicit_bzero(ctx->data,sizeof(pg_sha384_ctx));
214+
break;
215+
casePG_SHA512:
216+
explicit_bzero(ctx->data,sizeof(pg_sha512_ctx));
217+
break;
218+
}
219+
200220
FREE(ctx->data);
201221
explicit_bzero(ctx,sizeof(pg_cryptohash_ctx));
202222
FREE(ctx);

‎src/common/md5_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bytesToHex(uint8 b[16], char *s)
6969
bool
7070
pg_md5_hash(constvoid*buff,size_tlen,char*hexsum)
7171
{
72-
uint8sum[16];
72+
uint8sum[MD5_DIGEST_LENGTH];
7373
pg_cryptohash_ctx*ctx;
7474

7575
ctx=pg_cryptohash_create(PG_MD5);

‎src/include/common/md5.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#ifndefPG_MD5_H
1717
#definePG_MD5_H
1818

19+
/* Size of result generated by MD5 computation */
20+
#defineMD5_DIGEST_LENGTH 16
21+
22+
/* password-related data */
1923
#defineMD5_PASSWD_CHARSET"0123456789abcdef"
2024
#defineMD5_PASSWD_LEN35
2125

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp