--- uuid.c 2004/01/09 21:59:57 1.9
+++ uuid.c 2004/01/10 10:49:00 1.10
@@ -40,6 +40,7 @@
#include "config.h"
#include "uuid.h"
+#include "uuid_md5.h"
#include "uuid_ui64.h"
/* determine types of 8-bit size */
@@ -488,13 +489,73 @@
return UUID_RC_OK;
}
+/*
+ * UUID Namespace Ids as pre-defined by draft-leach-uuids-guids-01.txt
+ * (defined here as network byte ordered octet stream for direct MD5 feeding)
+ */
+struct {
+ char *name;
+ uuid_uint8_t uuid[UUID_LEN_BIN];
+} uuid_ns_table[] = {
+ { "DNS", /* 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */
+ { 0x6b,0xa7,0xb8,0x10,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } },
+ { "URL", /* 6ba7b811-9dad-11d1-80b4-00c04fd430c8 */
+ { 0x6b,0xa7,0xb8,0x11,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } },
+ { "OID", /* 6ba7b812-9dad-11d1-80b4-00c04fd430c8 */
+ { 0x6b,0xa7,0xb8,0x12,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } },
+ { "X500", /* 6ba7b814-9dad-11d1-80b4-00c04fd430c8 */
+ { 0x6b,0xa7,0xb8,0x14,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8 } }
+};
+
/* generate UUID version 3: name based */
static uuid_rc_t uuid_generate_v3(uuid_t *uuid, unsigned int mode, va_list ap)
{
- /* brand with version and variant */
- uuid_brand(uuid, 3);
+ char *str;
+ char *ns_name;
+ void *ns_uuid;
+ md5_t *md5;
+ int i;
- /* FIXME */
+ /* determine namespace UUID name and argument name string */
+ if ((ns_name = (char *)va_arg(ap, char *)) == NULL)
+ return UUID_RC_ARG;
+ if ((str = (char *)va_arg(ap, char *)) == NULL)
+ return UUID_RC_ARG;
+
+ /* create MD5 context */
+ if (md5_create(&md5) != MD5_RC_OK)
+ return UUID_RC_MEM;
+
+ /* load the namespace UUID into MD5 context */
+ ns_uuid = NULL;
+ for (i = 0; i < sizeof(uuid_ns_table)/sizeof(uuid_ns_table[0]); i++) {
+ if (strcmp(uuid_ns_table[i].name, ns_name) == 0) {
+ ns_uuid = uuid_ns_table[i].uuid;
+ break;
+ }
+ }
+ if (ns_uuid == NULL)
+ return UUID_RC_ARG;
+ md5_update(md5, ns_uuid, UUID_LEN_BIN);
+
+ /* load the argument name string into MD5 context */
+ md5_update(md5, str, strlen(str));
+
+ /* store MD5 result into UUID
+ (requires MD5_LEN_BIN space, UUID_LEN_BIN space is available,
+ and both are equal in size, so we are safe!) */
+ md5_store(md5, (void *)&uuid, NULL);
+
+ /* destroy MD5 context */
+ md5_destroy(md5);
+
+ /* fulfill requirement of standard and convert UUID data into
+ local/host byte order (this uses fact that uuid_unpack() is
+ able to operate in-place!) */
+ uuid_unpack(uuid, (void *)uuid);
+
+ /* brand UUID with version and variant */
+ uuid_brand(uuid, 3);
return UUID_RC_OK;
}
@@ -502,10 +563,10 @@
/* generate UUID version 4: random number based */
static uuid_rc_t uuid_generate_v4(uuid_t *uuid, unsigned int mode, va_list ap)
{
- /* fill with random data */
+ /* fill UUID with random data */
uuid_prng_getdata((void *)uuid, sizeof(uuid_t));
- /* brand with version and variant */
+ /* brand UUID with version and variant */
uuid_brand(uuid, 4);
return UUID_RC_OK;
|