Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /opt/src/cvs/pgsql-server/doc/src/sgml/func.sgml,v
retrieving revision 1.133
diff -c -r1.133 func.sgml
*** doc/src/sgml/func.sgml 5 Dec 2002 04:38:29 -0000 1.133
--- doc/src/sgml/func.sgml 5 Dec 2002 05:16:55 -0000
***************
*** 1140,1145 ****
--- 1140,1155 ----
+ md5(string text)
+ text
+
+ Calculates the MD5 hash of given string, returning the result in hex.
+
+ md5('abc')
+ 900150983cd24fb0d6963f7d28e17f72
+
+
+
pg_client_encoding()
name
Index: src/backend/utils/adt/varlena.c
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/backend/utils/adt/varlena.c,v
retrieving revision 1.93
diff -c -r1.93 varlena.c
*** src/backend/utils/adt/varlena.c 17 Nov 2002 23:01:30 -0000 1.93
--- src/backend/utils/adt/varlena.c 5 Dec 2002 04:36:11 -0000
***************
*** 23,28 ****
--- 23,29 ----
#include "utils/builtins.h"
#include "utils/pg_locale.h"
+ extern bool md5_hash(const void *buff, size_t len, char *hexsum);
typedef struct varlena unknown;
***************
*** 1837,1841 ****
--- 1838,1868 ----
} while (ptr > buf && value);
result_text = PG_STR_GET_TEXT(ptr);
+ PG_RETURN_TEXT_P(result_text);
+ }
+
+ /*
+ * Create an md5 hash of a text string and return it as hex
+ *
+ * md5 produces a 16 byte (128 bit) hash; double it for hex
+ */
+ #define MD5_HASH_LEN 32
+
+ Datum
+ md5_text(PG_FUNCTION_ARGS)
+ {
+ char *buff = PG_TEXT_GET_STR(PG_GETARG_TEXT_P(0));
+ size_t len = strlen(buff);
+ char *hexsum;
+ text *result_text;
+
+ /* leave room for the terminating '\0' */
+ hexsum = (char *) palloc(MD5_HASH_LEN + 1);
+
+ /* get the hash result */
+ md5_hash((void *) buff, len, hexsum);
+
+ /* convert to text and return it */
+ result_text = PG_STR_GET_TEXT(hexsum);
PG_RETURN_TEXT_P(result_text);
}
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/include/catalog/pg_proc.h,v
retrieving revision 1.278
diff -c -r1.278 pg_proc.h
*** src/include/catalog/pg_proc.h 5 Dec 2002 04:38:30 -0000 1.278
--- src/include/catalog/pg_proc.h 5 Dec 2002 04:44:54 -0000
***************
*** 3121,3126 ****
--- 3121,3129 ----
DATA(insert OID = 2307 ( opaque_out PGNSP PGUID 12 f f t f i 1 2275 "2282" opaque_out - _null_ ));
DESCR("(internal)");
+ /* cryptographic */
+ DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 f f t f i 1 25 "25" md5_text - _null_ ));
+ DESCR("calculates md5 hash");
/*
* Symbolic values for provolatile column: these indicate whether the result
Index: src/include/utils/builtins.h
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/include/utils/builtins.h,v
retrieving revision 1.205
diff -c -r1.205 builtins.h
*** src/include/utils/builtins.h 8 Nov 2002 17:37:52 -0000 1.205
--- src/include/utils/builtins.h 5 Dec 2002 04:56:37 -0000
***************
*** 482,487 ****
--- 482,488 ----
extern Datum split_text(PG_FUNCTION_ARGS);
extern Datum to_hex32(PG_FUNCTION_ARGS);
extern Datum to_hex64(PG_FUNCTION_ARGS);
+ extern Datum md5_text(PG_FUNCTION_ARGS);
extern Datum unknownin(PG_FUNCTION_ARGS);
extern Datum unknownout(PG_FUNCTION_ARGS);