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

Commit0c0dde6

Browse files
committed
Hashing functions from Marko Kreen <marko@l-t.ee>
1 parent73874a0 commit0c0dde6

File tree

14 files changed

+1450
-1
lines changed

14 files changed

+1450
-1
lines changed

‎contrib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.8 2000/09/18 20:11:34 petere Exp $
1+
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.9 2000/10/31 13:11:28 petere Exp $
22

33
subdir = contrib
44
top_builddir = ..
@@ -17,6 +17,7 @@ WANTED_DIRS =array\
1717
noupdate\
1818
pg_dumplo\
1919
pgbench\
20+
pgcrypto\
2021
soundex\
2122
spi\
2223
string\

‎contrib/pgcrypto/Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# $Header: /cvsroot/pgsql/contrib/pgcrypto/Makefile,v 1.1 2000/10/31 13:11:28 petere Exp $
3+
#
4+
5+
subdir = contrib/pgcrypto
6+
top_builddir = ../..
7+
include$(top_builddir)/src/Makefile.global
8+
9+
# either 'builtin', 'mhash', 'openssl', 'krb5'
10+
cryptolib = builtin
11+
12+
##########################
13+
14+
ifeq ($(cryptolib), builtin)
15+
SRCS= md5.c sha1.c internal.c
16+
endif
17+
18+
ifeq ($(cryptolib), openssl)
19+
cryptoinc := -I/usr/include/openssl
20+
cryptolib := -lcrypto
21+
SRCS = openssl.c
22+
endif
23+
24+
ifeq ($(cryptolib), mhash)
25+
cryptoinc=
26+
cryptolib=-lmhash
27+
SRCS=mhash.c
28+
endif
29+
30+
ifeq ($(cryptolib), krb5)
31+
cryptoinc=-I/usr/include
32+
cryptolib=-ldes
33+
SRCS=krb.c
34+
endif
35+
36+
NAME:= pgcrypto
37+
SRCS+= pgcrypto.c
38+
OBJS:=$(SRCS:.c=.o)
39+
SO_MAJOR_VERSION = 0
40+
SO_MINOR_VERSION = 1
41+
42+
overrideCPPFLAGS+= -I$(srcdir)$(cryptoinc)
43+
44+
all: all-lib$(NAME).sql
45+
46+
include$(top_srcdir)/src/Makefile.shlib
47+
48+
$(NAME).sql:$(NAME).sql.in
49+
sed's,@MODULE_FILENAME@,$(libdir)/contrib/pgcrypto$(DLSUFFIX),g'$<>$@
50+
51+
install: all installdirs
52+
$(INSTALL_SHLIB)$(shlib)$(DESTDIR)$(libdir)/contrib/pgcrypto$(DLSUFFIX)
53+
$(INSTALL_DATA)$(NAME).sql$(DESTDIR)$(datadir)/contrib/$(NAME).sql
54+
$(INSTALL_DATA) README.$(NAME)$(DESTDIR)$(docdir)/contrib/README.$(NAME)
55+
56+
installdirs:
57+
$(mkinstalldirs)$(libdir)/contrib$(datadir)/contrib$(docdir)/contrib
58+
59+
uninstall: uninstall-lib
60+
rm -f$(DESTDIR)$(libdir)/contrib/pgcrypto$(DLSUFFIX)$(datadir)/contrib/$(NAME).sql$(docdir)/contrib/README.$(NAME)
61+
62+
cleandistcleanmaintainer-clean: clean-lib
63+
rm -f$(OBJS)$(NAME).sql

‎contrib/pgcrypto/README.pgcrypto

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
DESCRIPTION
3+
4+
Here is a implementation of crypto hashes for PostgreSQL.
5+
It exports 2 functions to SQL level:
6+
7+
digest(data::text, hash_name::text)
8+
which returns hexadecimal coded hash over data by
9+
specified algorithm. eg
10+
11+
> select digest('blah', 'sha1');
12+
5bf1fd927dfb8679496a2e6cf00cbe50c1c87145
13+
14+
digest_exists(hash_name::text)::bool
15+
which reports if particular hash type exists.
16+
17+
If any of arguments are NULL they return NULL.
18+
19+
HASHES
20+
21+
For choosing library you must edit Makefile.
22+
23+
standalone (default):
24+
MD5, SHA1
25+
26+
(the code is from KAME project. Actually I hate code
27+
duplication, but I also want to quarantee that MD5 and
28+
SHA1 exist)
29+
30+
mhash (0.8.1):
31+
MD5, SHA1, CRC32, CRC32B, GOST, TIGER, RIPEMD160,
32+
HAVAL(256,224,192,160,128)
33+
34+
openssl:
35+
MD5, SHA1, RIPEMD160, MD2
36+
37+
kerberos5 (heimdal):
38+
MD5, SHA1
39+
40+

‎contrib/pgcrypto/internal.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* internal.c
3+
*Wrapper for builtin functions
4+
*
5+
* Copyright (c) 2000 Marko Kreen
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
* 1. Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
* SUCH DAMAGE.
28+
*
29+
* $Id: internal.c,v 1.1 2000/10/31 13:11:28 petere Exp $
30+
*/
31+
32+
#include<postgres.h>
33+
34+
#include"pgcrypto.h"
35+
36+
#include"md5.h"
37+
#include"sha1.h"
38+
39+
#ifndefMD5_DIGEST_LENGTH
40+
#defineMD5_DIGEST_LENGTH 16
41+
#endif
42+
43+
#ifndefSHA1_DIGEST_LENGTH
44+
#ifdefSHA1_RESULTLEN
45+
#defineSHA1_DIGEST_LENGTH SHA1_RESULTLEN
46+
#else
47+
#defineSHA1_DIGEST_LENGTH 20
48+
#endif
49+
#endif
50+
51+
staticuint
52+
pg_md5_len(pg_digest*h);
53+
staticuint8*
54+
pg_md5_digest(pg_digest*h,uint8*src,uintlen,uint8*buf);
55+
56+
staticuint
57+
pg_sha1_len(pg_digest*h);
58+
staticuint8*
59+
pg_sha1_digest(pg_digest*h,uint8*src,uintlen,uint8*buf);
60+
61+
staticpg_digest
62+
int_digest_list []= {
63+
{"md5",pg_md5_len,pg_md5_digest, {0}},
64+
{"sha1",pg_sha1_len,pg_sha1_digest, {0}},
65+
{NULL,NULL,NULL, {0}}
66+
};
67+
68+
staticuint
69+
pg_md5_len(pg_digest*h) {
70+
returnMD5_DIGEST_LENGTH;
71+
}
72+
73+
staticuint8*
74+
pg_md5_digest(pg_digest*h,uint8*src,uintlen,uint8*buf)
75+
{
76+
MD5_CTXctx;
77+
78+
MD5Init(&ctx);
79+
MD5Update(&ctx,src,len);
80+
MD5Final(buf,&ctx);
81+
82+
returnbuf;
83+
}
84+
85+
staticuint
86+
pg_sha1_len(pg_digest*h) {
87+
returnSHA1_DIGEST_LENGTH;
88+
}
89+
90+
staticuint8*
91+
pg_sha1_digest(pg_digest*h,uint8*src,uintlen,uint8*buf)
92+
{
93+
SHA1_CTXctx;
94+
95+
SHA1Init(&ctx);
96+
SHA1Update(&ctx,src,len);
97+
SHA1Final(buf,&ctx);
98+
99+
returnbuf;
100+
}
101+
102+
103+
pg_digest*
104+
pg_find_digest(pg_digest*h,char*name)
105+
{
106+
pg_digest*p;
107+
108+
for (p=int_digest_list;p->name;p++)
109+
if (!strcasecmp(p->name,name))
110+
returnp;
111+
returnNULL;
112+
}
113+
114+

‎contrib/pgcrypto/krb.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* krb.c
3+
*Wrapper for Kerberos5 libdes SHA1/MD5.
4+
*
5+
* Copyright (c) 2000 Marko Kreen
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
* 1. Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
* SUCH DAMAGE.
28+
*
29+
*
30+
* NOTES
31+
*It is possible that this works with other SHA1/MD5
32+
*implementations too.
33+
*
34+
* $Id: krb.c,v 1.1 2000/10/31 13:11:28 petere Exp $
35+
*/
36+
37+
#include<postgres.h>
38+
39+
#include"pgcrypto.h"
40+
41+
#include<md5.h>
42+
#include<sha.h>
43+
44+
#ifndefMD5_DIGEST_LENGTH
45+
#defineMD5_DIGEST_LENGTH 16
46+
#endif
47+
48+
#ifndefSHA1_DIGEST_LENGTH
49+
#ifdefSHA1_RESULTLEN
50+
#defineSHA1_DIGEST_LENGTH SHA1_RESULTLEN
51+
#else
52+
#defineSHA1_DIGEST_LENGTH 20
53+
#endif
54+
#endif
55+
56+
staticuint
57+
pg_md5_len(pg_digest*h);
58+
staticuint8*
59+
pg_md5_digest(pg_digest*h,uint8*src,uintlen,uint8*buf);
60+
61+
staticuint
62+
pg_sha1_len(pg_digest*h);
63+
staticuint8*
64+
pg_sha1_digest(pg_digest*h,uint8*src,uintlen,uint8*buf);
65+
66+
staticpg_digest
67+
int_digest_list []= {
68+
{"md5",pg_md5_len,pg_md5_digest, {0}},
69+
{"sha1",pg_sha1_len,pg_sha1_digest, {0}},
70+
{NULL,NULL,NULL, {0}}
71+
};
72+
73+
staticuint
74+
pg_md5_len(pg_digest*h) {
75+
returnMD5_DIGEST_LENGTH;
76+
}
77+
78+
staticuint8*
79+
pg_md5_digest(pg_digest*h,uint8*src,uintlen,uint8*buf)
80+
{
81+
MD5_CTXctx;
82+
83+
MD5Init(&ctx);
84+
MD5Update(&ctx,src,len);
85+
MD5Final(buf,&ctx);
86+
87+
returnbuf;
88+
}
89+
90+
staticuint
91+
pg_sha1_len(pg_digest*h) {
92+
returnSHA1_DIGEST_LENGTH;
93+
}
94+
95+
staticuint8*
96+
pg_sha1_digest(pg_digest*h,uint8*src,uintlen,uint8*buf)
97+
{
98+
SHA1_CTXctx;
99+
100+
SHA1Init(&ctx);
101+
SHA1Update(&ctx,src,len);
102+
SHA1Final(buf,&ctx);
103+
104+
returnbuf;
105+
}
106+
107+
108+
pg_digest*
109+
pg_find_digest(pg_digest*h,char*name)
110+
{
111+
pg_digest*p;
112+
113+
for (p=int_digest_list;p->name;p++)
114+
if (!strcasecmp(p->name,name))
115+
returnp;
116+
returnNULL;
117+
}
118+
119+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp