Index: ossp-pkg/uuid/uuid.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v' 2>/dev/null --- 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; Index: ossp-pkg/uuid/uuid_cli.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.c,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.c,v' 2>/dev/null --- uuid_cli.c 2004/01/09 21:01:04 1.6 +++ uuid_cli.c 2004/01/10 10:49:00 1.7 @@ -145,7 +145,9 @@ } else { /* encoding */ - if (argc < 0 || ((version == UUID_VERSION3 && argc > 2) || argc > 1)) + if ( (version == UUID_VERSION1 && argc != 0) + || (version == UUID_VERSION3 && argc != 2) + || (version == UUID_VERSION4 && argc != 0)) usage("invalid number of arguments"); if ((rc = uuid_create(&uuid)) != UUID_RC_OK) error(1, "uuid_create: %s", uuid_error(rc)); @@ -160,7 +162,7 @@ error(1, "uuid_nil: %s", uuid_error(rc)); } if (version == UUID_VERSION3) - rc = uuid_generate(uuid, version, argv[0]); + rc = uuid_generate(uuid, version, argv[0], argv[1]); else rc = uuid_generate(uuid, version); if (rc != UUID_RC_OK) Index: ossp-pkg/uuid/uuid_md5.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_md5.c,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_md5.c,v' 2>/dev/null --- uuid_md5.c 2004/01/09 15:51:20 1.2 +++ uuid_md5.c 2004/01/10 10:49:00 1.3 @@ -388,10 +388,11 @@ *data_len = MD5_LEN_BIN; } else { - if (data_len == NULL) - return MD5_RC_ARG; - if (*data_len < MD5_LEN_BIN) - return MD5_RC_MEM; + if (data_len != NULL) { + if (*data_len < MD5_LEN_BIN) + return MD5_RC_MEM; + *data_len = MD5_LEN_BIN; + } } memcpy((void *)(&ctx), (void *)(&(md5->ctx)), sizeof(MD5_CTX)); MD5Final((unsigned char *)(*data_ptr), &(md5->ctx)); @@ -417,10 +418,11 @@ *data_len = MD5_LEN_STR+1; } else { - if (data_len == NULL) - return MD5_RC_ARG; - if (*data_len < (MD5_LEN_STR+1)) - return MD5_RC_MEM; + if (data_len != NULL) { + if (*data_len < MD5_LEN_STR+1) + return MD5_RC_MEM; + *data_len = MD5_LEN_STR+1; + } } bufptr = buf;