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

Commita8ed6bb

Browse files
committed
Introduce SHA1 implementations in the cryptohash infrastructure
With this commit, SHA1 goes through the implementation provided byOpenSSL via EVP when building the backend with it, and uses as fallbackimplementation KAME which was located in pgcrypto and already shaped foran integration with a set of init, update and final routines.Structures and routines have been renamed to make things consistent withthe fallback implementations of MD5 and SHA2.uuid-ossp has used for ages a shortcut with pgcrypto to fetch a copy ofSHA1 if needed. This was built depending on the build options within./configure, so this cleans up some code and removes the builddependency between pgcrypto and uuid-ossp.Note that this will help with the refactoring of HMAC, as pgcryptooffers the option to use MD5, SHA1 or SHA2, so only the second optionwas missing to make that possible.Author: Michael PaquierReviewed-by: Heikki LinnakangasDiscussion:https://postgr.es/m/X9HXKTgrvJvYO7Oh@paquier.xyz
1 parent3fc81ce commita8ed6bb

File tree

18 files changed

+479
-424
lines changed

18 files changed

+479
-424
lines changed

‎configure

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,6 @@ XML2_LIBS
705705
XML2_CFLAGS
706706
XML2_CONFIG
707707
with_libxml
708-
UUID_EXTRA_OBJS
709708
with_uuid
710709
with_readline
711710
with_systemd
@@ -8303,30 +8302,26 @@ if test "$with_ossp_uuid" = yes ; then
83038302
with_uuid=ossp
83048303
fi
83058304

8306-
if test "$with_uuid" = bsd ; then
8305+
if test "$with_uuid" != no ; then
8306+
if test "$with_uuid" = bsd ; then
83078307

83088308
$as_echo "#define HAVE_UUID_BSD 1" >>confdefs.h
83098309

8310-
UUID_EXTRA_OBJS="sha1.o"
8311-
elif test "$with_uuid" = e2fs ; then
8310+
elif test "$with_uuid" = e2fs ; then
83128311

83138312
$as_echo "#define HAVE_UUID_E2FS 1" >>confdefs.h
83148313

8315-
UUID_EXTRA_OBJS="sha1.o"
8316-
elif test "$with_uuid" = ossp ; then
8314+
elif test "$with_uuid" = ossp ; then
83178315

83188316
$as_echo "#define HAVE_UUID_OSSP 1" >>confdefs.h
83198317

8320-
UUID_EXTRA_OBJS=""
8321-
elif test "$with_uuid" = no ; then
8322-
UUID_EXTRA_OBJS=""
8323-
else
8324-
as_fn_error $? "--with-uuid must specify one of bsd, e2fs, or ossp" "$LINENO" 5
8318+
else
8319+
as_fn_error $? "--with-uuid must specify one of bsd, e2fs, or ossp" "$LINENO" 5
8320+
fi
83258321
fi
83268322

83278323

83288324

8329-
83308325
#
83318326
# XML
83328327
#

‎configure.ac

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -919,22 +919,18 @@ if test "$with_ossp_uuid" = yes ; then
919919
with_uuid=ossp
920920
fi
921921

922-
if test "$with_uuid" = bsd ; then
923-
AC_DEFINE([HAVE_UUID_BSD],1,[Define to 1 if you have BSD UUID support.])
924-
UUID_EXTRA_OBJS="sha1.o"
925-
elif test "$with_uuid" = e2fs ; then
926-
AC_DEFINE([HAVE_UUID_E2FS],1,[Define to 1 if you have E2FS UUID support.])
927-
UUID_EXTRA_OBJS="sha1.o"
928-
elif test "$with_uuid" = ossp ; then
929-
AC_DEFINE([HAVE_UUID_OSSP],1,[Define to 1 if you have OSSP UUID support.])
930-
UUID_EXTRA_OBJS=""
931-
elif test "$with_uuid" = no ; then
932-
UUID_EXTRA_OBJS=""
933-
else
934-
AC_MSG_ERROR([--with-uuid must specify one of bsd, e2fs, or ossp])
922+
if test "$with_uuid" != no ; then
923+
if test "$with_uuid" = bsd ; then
924+
AC_DEFINE([HAVE_UUID_BSD],1,[Define to 1 if you have BSD UUID support.])
925+
elif test "$with_uuid" = e2fs ; then
926+
AC_DEFINE([HAVE_UUID_E2FS],1,[Define to 1 if you have E2FS UUID support.])
927+
elif test "$with_uuid" = ossp ; then
928+
AC_DEFINE([HAVE_UUID_OSSP],1,[Define to 1 if you have OSSP UUID support.])
929+
else
930+
AC_MSG_ERROR([--with-uuid must specify one of bsd, e2fs, or ossp])
931+
fi
935932
fi
936933
AC_SUBST(with_uuid)
937-
AC_SUBST(UUID_EXTRA_OBJS)
938934

939935

940936
#

‎contrib/pgcrypto/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# contrib/pgcrypto/Makefile
22

3-
INT_SRCS =sha1.cinternal.c internal-sha2.c blf.c rijndael.c\
3+
INT_SRCS = internal.c internal-sha2.c blf.c rijndael.c\
44
pgp-mpi-internal.c imath.c
55
INT_TESTS = sha2
66

‎contrib/pgcrypto/internal.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,10 @@
3636
#include"blf.h"
3737
#include"px.h"
3838
#include"rijndael.h"
39-
#include"sha1.h"
4039

4140
#include"common/cryptohash.h"
4241
#include"common/md5.h"
43-
44-
#ifndefSHA1_DIGEST_LENGTH
45-
#ifdefSHA1_RESULTLEN
46-
#defineSHA1_DIGEST_LENGTH SHA1_RESULTLEN
47-
#else
48-
#defineSHA1_DIGEST_LENGTH 20
49-
#endif
50-
#endif
42+
#include"common/sha1.h"
5143

5244
#defineSHA1_BLOCK_SIZE 64
5345
#defineMD5_BLOCK_SIZE 64
@@ -144,34 +136,36 @@ int_sha1_block_len(PX_MD *h)
144136
staticvoid
145137
int_sha1_update(PX_MD*h,constuint8*data,unsigneddlen)
146138
{
147-
SHA1_CTX*ctx= (SHA1_CTX*)h->p.ptr;
139+
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
148140

149-
SHA1Update(ctx,data,dlen);
141+
if (pg_cryptohash_update(ctx,data,dlen)<0)
142+
elog(ERROR,"could not update %s context","SHA1");
150143
}
151144

152145
staticvoid
153146
int_sha1_reset(PX_MD*h)
154147
{
155-
SHA1_CTX*ctx= (SHA1_CTX*)h->p.ptr;
148+
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
156149

157-
SHA1Init(ctx);
150+
if (pg_cryptohash_init(ctx)<0)
151+
elog(ERROR,"could not initialize %s context","SHA1");
158152
}
159153

160154
staticvoid
161155
int_sha1_finish(PX_MD*h,uint8*dst)
162156
{
163-
SHA1_CTX*ctx= (SHA1_CTX*)h->p.ptr;
157+
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
164158

165-
SHA1Final(dst,ctx);
159+
if (pg_cryptohash_final(ctx,dst)<0)
160+
elog(ERROR,"could not finalize %s context","SHA1");
166161
}
167162

168163
staticvoid
169164
int_sha1_free(PX_MD*h)
170165
{
171-
SHA1_CTX*ctx= (SHA1_CTX*)h->p.ptr;
166+
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
172167

173-
px_memset(ctx,0,sizeof(*ctx));
174-
pfree(ctx);
168+
pg_cryptohash_free(ctx);
175169
pfree(h);
176170
}
177171

@@ -199,9 +193,9 @@ init_md5(PX_MD *md)
199193
staticvoid
200194
init_sha1(PX_MD*md)
201195
{
202-
SHA1_CTX*ctx;
196+
pg_cryptohash_ctx*ctx;
203197

204-
ctx=palloc0(sizeof(*ctx));
198+
ctx=pg_cryptohash_create(PG_SHA1);
205199

206200
md->p.ptr=ctx;
207201

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp