Index: ossp-pkg/uuid/ChangeLog RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/ChangeLog,v rcsdiff -q -kk '-r1.67' '-r1.68' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/ChangeLog,v' 2>/dev/null --- ChangeLog 2005/01/13 10:37:36 1.67 +++ ChangeLog 2005/01/23 11:28:51 1.68 @@ -11,6 +11,12 @@ This is a list of all changes to OSSP uuid. For a more brief summary please have a look at the NEWS file. + Changes between 1.1.2 and 1.2.0 (13-Jan-2005 to xx-Jan-2005) + + o Added support for new version 5 UUIDs (name-based, SHA-1) + according to latest draft-mealling-uuid-urn-05.txt. + [Ralf S. Engelschall] + Changes between 1.1.1 and 1.1.2 (18-Nov-2004 to 13-Jan-2005) o Fix generation of v3 UUIDs by adding support for 64-bit platforms Index: ossp-pkg/uuid/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/Makefile.in,v rcsdiff -q -kk '-r1.25' '-r1.26' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/Makefile.in,v' 2>/dev/null --- Makefile.in 2004/12/31 19:20:34 1.25 +++ Makefile.in 2005/01/23 11:28:51 1.26 @@ -56,7 +56,7 @@ PERL = @PERL@ LIB_NAME = libuuid.la -LIB_OBJS = uuid.lo uuid_md5.lo uuid_prng.lo uuid_mac.lo uuid_ui64.lo uuid_str.lo +LIB_OBJS = uuid.lo uuid_md5.lo uuid_sha1.lo uuid_prng.lo uuid_mac.lo uuid_ui64.lo uuid_str.lo DCE_NAME = libuuid_dce.la DCE_OBJS = $(LIB_OBJS) uuid_dce.lo @@ -100,9 +100,10 @@ @cd perl && $(PERL) Makefile.PL PREFIX=$(prefix) && $(MAKE) $(MFLAGS) all @touch $(PERL_NAME) -uuid.lo: uuid.c config.h uuid.h uuid_md5.h uuid_prng.h uuid_mac.h uuid_ui64.h uuid_str.h uuid_bm.h uuid_ac.h +uuid.lo: uuid.c config.h uuid.h uuid_md5.h uuid_sha1.h uuid_prng.h uuid_mac.h uuid_ui64.h uuid_str.h uuid_bm.h uuid_ac.h uuid_mac.lo: uuid_mac.c config.h uuid_mac.h uuid_md5.lo: uuid_md5.c uuid_md5.h +uuid_sha1.lo: uuid_sha1.c uuid_sha1.h uuid_prng.lo: uuid_prng.c uuid_prng.h uuid_str.lo: uuid_str.c config.h uuid_str.h uuid_ui64.lo: uuid_ui64.c uuid_ui64.h @@ -142,8 +143,10 @@ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -n 4 -1 @echo "==== UUID version 1 (time and node based): 4 subsequent iterations"; \ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -n 4 - @echo "==== UUID version 3 (name based): 2 times repeated"; \ + @echo "==== UUID version 3 (name based, MD5): 2 times repeated"; \ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v3 -n 2 ns:URL http://www.ossp.org/ + @echo "==== UUID version 5 (name based, SHA-1): 2 times repeated"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v5 -n 2 ns:URL http://www.ossp.org/ @echo "==== UUID version 4 (random data based): 4 single iterations"; \ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4 -n 4 -1 @echo "==== UUID version 4 (random data based): 4 subsequent iterations"; \ @@ -153,6 +156,8 @@ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -m` @echo "==== UUID version 3 generation and decoding"; \ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v3 ns:URL http://www.ossp.org/` + @echo "==== UUID version 5 generation and decoding"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v5 ns:URL http://www.ossp.org/` @echo "==== UUID version 3 generation and decoding"; \ $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4` -@if [ ".$(WITH_PERL)" = .yes ]; then \ Index: ossp-pkg/uuid/NEWS RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/NEWS,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/NEWS,v' 2>/dev/null --- NEWS 2004/01/11 08:54:18 1.2 +++ NEWS 2005/01/23 11:28:51 1.3 @@ -11,5 +11,10 @@ This is a list of major changes to OSSP uuid. For more detailed change descriptions, please have a look at the ChangeLog file. - -NONE- + Changes between 1.1 and 1.2 + o Added support for version 5 UUIDs (name-based, SHA-1) + Changes between 1.0 and 1.1 + o Added Perl API + Changes between 0.9 and 1.0 + o Initial functionality Index: ossp-pkg/uuid/README RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/README,v rcsdiff -q -kk '-r1.24' '-r1.25' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/README,v' 2>/dev/null --- README 2005/01/13 10:37:36 1.24 +++ README 2005/01/23 11:28:51 1.25 @@ -5,7 +5,7 @@ |_|_|_| \___/|____/____/|_| \__,_|\__,_|_|\__,_| OSSP uuid - Universally Unique Identifier - Version 1.1.2 (13-Jan-2005) + Version 1.2.0 (23-Jan-2005) ABSTRACT @@ -13,7 +13,8 @@ and corresponding command line interface (CLI) for the generation of DCE 1.1 and ISO/IEC 11578:1996 compliant Universally Unique Identifier (UUID). It supports DCE 1.1 variant UUIDs of version 1 (time and node - based), version 3 (name based) and version 4 (random number based). + based), version 3 (name based, MD5), version 4 (random number based) + and version 5 (name based, SHA-1). UUIDs are 128 bit numbers which are intended to have a high likelihood of uniqueness over space and time and are computationally difficult Index: ossp-pkg/uuid/perl/uuid.pm RCS File: /v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.pm,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.pm,v' 2>/dev/null --- uuid.pm 2005/01/13 10:37:37 1.6 +++ uuid.pm 2005/01/23 11:28:54 1.7 @@ -41,7 +41,7 @@ ## # API version -our $VERSION = do { my @v = ('1.1.2' =~ m/\d+/g); sprintf("%d.".("%02d"x$#v), @v); }; +our $VERSION = do { my @v = ('1.2.0' =~ m/\d+/g); sprintf("%d.".("%02d"x$#v), @v); }; # API inheritance our @ISA = qw(Exporter); Index: ossp-pkg/uuid/uuid.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v rcsdiff -q -kk '-r1.49' '-r1.50' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v' 2>/dev/null --- uuid.c 2004/12/31 19:20:34 1.49 +++ uuid.c 2005/01/23 11:28:51 1.50 @@ -45,6 +45,7 @@ #include "uuid.h" #include "uuid_vers.h" #include "uuid_md5.h" +#include "uuid_sha1.h" #include "uuid_prng.h" #include "uuid_mac.h" #include "uuid_ui64.h" @@ -83,6 +84,7 @@ uuid_obj_t obj; /* inlined UUID object */ prng_t *prng; /* RPNG sub-object */ md5_t *md5; /* MD5 sub-object */ + sha1_t *sha1; /* SHA-1 sub-object */ uuid_uint8_t mac[IEEE_MAC_OCTETS]; /* pre-determined MAC address */ struct timeval time_last; /* last retrieved timestamp */ unsigned long time_seq; /* last timestamp sequence counter */ @@ -107,6 +109,8 @@ return UUID_RC_INT; if (md5_create(&(*uuid)->md5) != MD5_RC_OK) return UUID_RC_INT; + if (sha1_create(&(*uuid)->sha1) != SHA1_RC_OK) + return UUID_RC_INT; /* resolve MAC address for insertion into node field of UUIDs */ if (!mac_address((unsigned char *)((*uuid)->mac), sizeof((*uuid)->mac))) { @@ -129,9 +133,10 @@ if (uuid == NULL) return UUID_RC_ARG; - /* destroy PRNG and MD5 sub-objects */ + /* destroy PRNG, MD5 and SHA-1 sub-objects */ prng_destroy(uuid->prng); md5_destroy(uuid->md5); + sha1_destroy(uuid->sha1); /* free UUID object */ free(uuid); @@ -443,8 +448,9 @@ const char *desc; } uuid_dectab_version[] = { { 1, "time and node based" }, - { 3, "name based" }, - { 4, "random data based" } + { 3, "name based, MD5" }, + { 4, "random data based" }, + { 5, "name based, SHA-1" } }; /* INTERNAL: dump UUID object as descriptive text */ @@ -569,13 +575,15 @@ /* decode anything else as hexadecimal byte-string only */ /* determine annotational hint */ - content = "not decipherable, because unknown UUID version"; + content = "not decipherable: unknown UUID version"; if (isnil) - content = "special case of DCE 1.1 Nil UUID"; + content = "special case: DCE 1.1 Nil UUID"; else if (tmp16 == 3) - content = "not decipherable, because message digest only"; + content = "not decipherable: MD5 message digest only"; else if (tmp16 == 4) - content = "no semantics, because random data only"; + content = "no semantics: random data only"; + else if (tmp16 == 5) + content = "not decipherable: truncated SHA-1 message digest only"; /* pack UUID into binary representation */ tmp_ptr = (void *)&tmp_bin; @@ -852,7 +860,7 @@ return UUID_RC_OK; } -/* INTERNAL: generate UUID version 3: name based */ +/* INTERNAL: generate UUID version 3: name based with MD5 */ static uuid_rc_t uuid_make_v3(uuid_t *uuid, unsigned int mode, va_list ap) { char *str; @@ -909,6 +917,56 @@ return UUID_RC_OK; } +/* INTERNAL: generate UUID version 5: name based with SHA-1 */ +static uuid_rc_t uuid_make_v5(uuid_t *uuid, unsigned int mode, va_list ap) +{ + char *str; + uuid_t *uuid_ns; + uuid_uint8_t uuid_buf[UUID_LEN_BIN]; + void *uuid_ptr; + size_t uuid_len; + uuid_uint8_t sha1_buf[SHA1_LEN_BIN]; + void *sha1_ptr; + + /* determine namespace UUID and name string arguments */ + if ((uuid_ns = (uuid_t *)va_arg(ap, void *)) == NULL) + return UUID_RC_ARG; + if ((str = (char *)va_arg(ap, char *)) == NULL) + return UUID_RC_ARG; + + /* initialize SHA-1 context */ + if (sha1_init(uuid->sha1) != MD5_RC_OK) + return UUID_RC_MEM; + + /* load the namespace UUID into SHA-1 context */ + uuid_ptr = (void *)&uuid_buf; + uuid_len = sizeof(uuid_buf); + uuid_export(uuid_ns, UUID_FMT_BIN, &uuid_ptr, &uuid_len); + sha1_update(uuid->sha1, uuid_buf, uuid_len); + + /* load the argument name string into SHA-1 context */ + sha1_update(uuid->sha1, str, strlen(str)); + + /* store SHA-1 result into UUID + (requires SHA1_LEN_BIN space, but UUID_LEN_BIN space is available + only, so use a temporary buffer to store SHA-1 results and then + use lower part only according to standard */ + sha1_ptr = (void *)sha1_buf; + sha1_store(uuid->sha1, &sha1_ptr, NULL); + uuid_ptr = (void *)&(uuid->obj); + memcpy(uuid_ptr, sha1_ptr, UUID_LEN_BIN); + + /* fulfill requirement of standard and convert UUID data into + local/host byte order (this uses fact that uuid_import_bin() is + able to operate in-place!) */ + uuid_import(uuid, UUID_FMT_BIN, (void *)&(uuid->obj), UUID_LEN_BIN); + + /* brand UUID with version and variant */ + uuid_brand(uuid, 5); + + return UUID_RC_OK; +} + /* generate UUID */ uuid_rc_t uuid_make(uuid_t *uuid, unsigned int mode, ...) { @@ -927,6 +985,8 @@ rc = uuid_make_v3(uuid, mode, ap); else if (mode & UUID_MAKE_V4) rc = uuid_make_v4(uuid, mode, ap); + else if (mode & UUID_MAKE_V5) + rc = uuid_make_v5(uuid, mode, ap); else rc = UUID_RC_ARG; va_end(ap); Index: ossp-pkg/uuid/uuid.h.in RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.h.in,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.h.in,v' 2>/dev/null --- uuid.h.in 2004/12/31 19:20:34 1.5 +++ uuid.h.in 2005/01/23 11:28:51 1.6 @@ -66,7 +66,8 @@ UUID_MAKE_V1 = (1 << 0), /* DCE 1.1 v1 UUID */ UUID_MAKE_V3 = (1 << 1), /* DCE 1.1 v3 UUID */ UUID_MAKE_V4 = (1 << 2), /* DCE 1.1 v4 UUID */ - UUID_MAKE_MC = (1 << 3) /* enforce multi-cast MAC address */ + UUID_MAKE_V5 = (1 << 3), /* DCE 1.1 v5 UUID */ + UUID_MAKE_MC = (1 << 4) /* enforce multi-cast MAC address */ }; /* UUID import/export formats */ Index: ossp-pkg/uuid/uuid.pod RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.pod,v rcsdiff -q -kk '-r1.24' '-r1.25' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.pod,v' 2>/dev/null --- uuid.pod 2005/01/22 18:55:57 1.24 +++ uuid.pod 2005/01/23 11:28:51 1.25 @@ -43,7 +43,8 @@ and corresponding command line interface (CLI) for the generation of DCE 1.1 and ISO/IEC 11578:1996 compliant I (UUID). It supports DCE 1.1 variant UUIDs of version 1 (time and node -based), version 3 (name based) and version 4 (random number based). +based), version 3 (name based, MD5), version 4 (random number based) and +version 5 (name based, SHA-1). UUIDs are 128 bit numbers which are intended to have a high likelihood of uniqueness over space and time and are computationally difficult @@ -125,7 +126,7 @@ (NIC) or a random multi-cast MAC address. Version 1 UUIDs are usually used as one-time global unique identifiers. -=item B (name based) +=item B (name based, MD5) These are UUIDs which are based on the 128-bit MD5 message digest of the concatenation of a 128-bit namespace UUID and a name string of arbitrary @@ -137,6 +138,13 @@ These are UUIDs which are based on just 128-bit of random data. Version 4 UUIDs are usually used as one-time local unique identifiers. +=item B (name based, SHA-1) + +These are UUIDs which are based on the 160-bit SHA-1 message digest of the +concatenation of a 128-bit namespace UUID and a name string of arbitrary +length. Version 5 UUIDs are usually used for non-unique but repeatable +message digest identifiers. + =back =head2 UUID Uniqueness @@ -154,8 +162,9 @@ backward), there is a random clock sequence component placed into the UUID as a "catch-all" for uniqueness. -Version 3 UUIDs are guaranteed to be inherently globally unique if the -combination of namespace and name used to generate them is unique. +Version 3 and version 5 UUIDs are guaranteed to be inherently globally +unique if the combination of namespace and name used to generate them is +unique. Version 4 UUIDs are not guaranteed to be globally unique, because they are generated out of locally gathered pseudo-random numbers only. @@ -197,7 +206,7 @@ Notice that the lengths of the string representation does I include the necessary C termination character. -=item B, B, B, B +=item B, B, B, B, B The I bits for use with B(). The BI specify which UUID version to generate. The B forces the @@ -297,7 +306,7 @@ =back The "CI" are names of pre-defined name-space UUIDs for use in -the generation of DCE 1.1 version 3 UUIDs. +the generation of DCE 1.1 version 3 and version 5 UUIDs. =item uuid_rc_t B(uuid_t *I, unsigned int I, ...); @@ -310,14 +319,14 @@ MAC address (the default). The UUID is generated out of the 60-bit current system time, a 12-bit clock sequence and the 48-bit MAC address. -If I contains the C bit, a DCE 1.1 variant UUID -of version 3 is generated and two additional C-terminated string -arguments of type "C" are expected: first a namespace, -given as an internally pre-defined id (currently known are ids "C", -"C", "C", and "C") or a UUID in string representation. -Second, a name string of arbitrary length. The UUID is generated out of -the 128-bit MD5 from the concatenated octet stream of namespace UUID and name -string. +If I contains the C or C bit, a DCE +1.1 variant UUID of version 3 or 5 is generated and two additional +C-terminated string arguments of type "C" are +expected: first a namespace, given as an internally pre-defined id +(currently known are ids "C", "C", "C", and "C") +or a UUID in string representation. Second, a name string of arbitrary +length. The UUID is generated out of the 128-bit MD5 or 160-bit SHA-1 +from the concatenated octet stream of namespace UUID and name string. If I contains the C bit, a DCE 1.1 variant UUID of version 4 is generated. The UUID is generated out of 128-bit random Index: ossp-pkg/uuid/uuid_cli.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.c,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.c,v' 2>/dev/null --- uuid_cli.c 2004/12/31 19:20:34 1.17 +++ uuid_cli.c 2005/01/23 11:28:51 1.18 @@ -62,7 +62,7 @@ vfprintf(stderr, str, ap); fprintf(stderr, "\n"); } - fprintf(stderr, "usage: uuid [-v version] [-m] [-n count] [-1] [-r] [-o filename] [namespace-name]\n"); + fprintf(stderr, "usage: uuid [-v version] [-m] [-n count] [-1] [-r] [-o filename] [namespace name]\n"); fprintf(stderr, "usage: uuid -d [-r] [-o filename] [uuid]\n"); va_end(ap); exit(1); @@ -130,6 +130,7 @@ case 1: version = UUID_MAKE_V1; break;; case 3: version = UUID_MAKE_V3; break;; case 4: version = UUID_MAKE_V4; break;; + case 5: version = UUID_MAKE_V5; break;; default: usage("invalid version on option 'v'"); break; @@ -188,7 +189,8 @@ /* encoding */ if ( (version == UUID_MAKE_V1 && argc != 0) || (version == UUID_MAKE_V3 && argc != 2) - || (version == UUID_MAKE_V4 && argc != 0)) + || (version == UUID_MAKE_V4 && argc != 0) + || (version == UUID_MAKE_V5 && argc != 2)) usage("invalid number of arguments"); if ((rc = uuid_create(&uuid)) != UUID_RC_OK) error(1, "uuid_create: %s", uuid_error(rc)); @@ -204,7 +206,7 @@ if ((rc = uuid_load(uuid, "nil")) != UUID_RC_OK) error(1, "uuid_load: %s", uuid_error(rc)); } - if (version == UUID_MAKE_V3) { + if (version == UUID_MAKE_V3 || version == UUID_MAKE_V5) { if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK) error(1, "uuid_create: %s", uuid_error(rc)); if ((rc = uuid_load(uuid_ns, argv[0])) != UUID_RC_OK) { Index: ossp-pkg/uuid/uuid_cli.pod RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.pod,v rcsdiff -q -kk '-r1.18' '-r1.19' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.pod,v' 2>/dev/null --- uuid_cli.pod 2004/12/31 19:20:34 1.18 +++ uuid_cli.pod 2005/01/23 11:28:51 1.19 @@ -60,7 +60,8 @@ and corresponding command line interface (CLI) for the generation of DCE 1.1 and ISO/IEC 11578:1996 compliant I (UUID). It supports DCE 1.1 variant UUIDs of version 1 (time and node -based), version 3 (name based) and version 4 (random number based). +based), version 3 (name based, MD5), version 4 (random number based) and +version 5 (name based, SHA-1). UUIDs are 128 bit numbers which are intended to have a high likelihood of uniqueness over space and time and are computationally difficult @@ -81,14 +82,14 @@ =item B<-v> I Sets the version of the generated DCE 1.1 variant UUID. Supported -are I "C<1>", "C<3>" and "C<4>". The default is "C<1>". +are I "C<1>", "C<3>", "C<4>" and "C<5>". The default is "C<1>". -For version 3 UUIDs the additional command line arguments I -and I have to be given. The I is either a UUID in -string representation or an identifier for internally pre-defined -namespace UUIDs (currently known are "C", "C", -"C", and "C"). The I is a string of arbitrary -length. +For version 3 and version 5 UUIDs the additional command line arguments +I and I have to be given. The I is either +a UUID in string representation or an identifier for internally +pre-defined namespace UUIDs (currently known are "C", +"C", "C", and "C"). The I is a string of +arbitrary length. =item B<-m> @@ -104,7 +105,7 @@ If option B<-n> is used with a I greater than C<1>, then this option can enforce the reset the UUID context for each generated UUID. -This makes no difference for I C<3> and C<4> UUIDs. But +This makes no difference for I C<3>, C<4> and C<5> UUIDs. But version C<1> UUIDs are based on the previously generated UUID which is remembered in the UUID context of the API. Option B<-1> deletes the remembered UUID on each iteration. Index: ossp-pkg/uuid/uuid_sha1.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_sha1.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_sha1.c,v' | diff -u /dev/null - -L'ossp-pkg/uuid/uuid_sha1.c' 2>/dev/null --- ossp-pkg/uuid/uuid_sha1.c +++ - 2024-05-21 07:38:03.593728105 +0200 @@ -0,0 +1,443 @@ +/* +** OSSP uuid - Universally Unique Identifier +** Copyright (c) 2004-2005 Ralf S. Engelschall +** Copyright (c) 2004-2005 The OSSP Project +** +** This file is part of OSSP uuid, a library for the generation +** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR +** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +** SUCH DAMAGE. +** +** uuid_sha1.c: SHA-1 API implementation +*/ + +#include +#include + +#include "config.h" +#include "uuid_sha1.h" + +/* + * This is a RFC 3174 compliant Secure Hash Function (SHA-1) algorithm + * implementation. It is directly derived from the SHA-1 reference + * code published in RFC 3174 with just the following functionality + * preserving changes: + * - reformatted C style to conform with OSSP C style + * - added own OSSP style frontend API + * - added Autoconf based determination of sha1_uintX_t types + */ + +/* +** ==== BEGIN RFC 3174 CODE ==== +*/ + +/* + * This implements the Secure Hashing Algorithm 1 as defined in + * FIPS PUB 180-1 published April 17, 1995. + * + * The SHA-1, produces a 160-bit message digest for a given data + * stream. It should take about 2**n steps to find a message with the + * same digest as a given message and 2**(n/2) to find any two messages + * with the same digest, when n is the digest size in bits. Therefore, + * this algorithm can serve as a means of providing a "fingerprint" for + * a message. + * + * Caveats: SHA-1 is designed to work with messages less than 2^64 bits + * long. Although SHA-1 allows a message digest to be generated for + * messages of any number of bits less than 2^64, this implementation + * only works with messages with a length that is a multiple of the + * size of an 8-bit character. + */ + +typedef unsigned char sha1_uint8_t; + +#if SIZEOF_SHORT > 2 +typedef short int sha1_int16plus_t; +#elif SIZEOF_INT > 2 +typedef int sha1_int16plus_t; +#elif SIZEOF_LONG > 2 +typedef long int sha1_int16plus_t; +#else +#error ERROR: unable to determine sha1_int16plus_t type (at least two byte word) +#endif + +#if SIZEOF_UNSIGNED_SHORT == 4 +typedef unsigned short int sha1_uint32_t; +#elif SIZEOF_UNSIGNED_INT == 4 +typedef unsigned int sha1_uint32_t; +#elif SIZEOF_UNSIGNED_LONG == 4 +typedef unsigned long int sha1_uint32_t; +#elif SIZEOF_UNSIGNED_LONG_LONG == 4 +typedef unsigned long long int sha1_uint32_t; +#else +#error ERROR: unable to determine sha1_uint32_t type (four byte word) +#endif + +enum { + shaSuccess = 0, + shaNull, /* null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError /* called Input after Result */ +}; + +#define SHA1HashSize 20 + +/* This structure will hold context information for the SHA-1 hashing operation */ +typedef struct SHA1Context { + sha1_uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ + sha1_uint32_t Length_Low; /* Message length in bits */ + sha1_uint32_t Length_High; /* Message length in bits */ + sha1_int16plus_t Message_Block_Index; /* Index into message block array */ + sha1_uint8_t Message_Block[64]; /* 512-bit message blocks */ + int Computed; /* Is the digest computed? */ + int Corrupted; /* Is the message digest corrupted? */ +} SHA1Context; + +/* Function Prototypes */ +static int SHA1Reset (SHA1Context *); +static int SHA1Input (SHA1Context *, const sha1_uint8_t *, unsigned int); +static int SHA1Result (SHA1Context *, sha1_uint8_t Message_Digest[SHA1HashSize]); + +/* Local Function Prototyptes */ +static void SHA1PadMessage (SHA1Context *); +static void SHA1ProcessMessageBlock(SHA1Context *); + +/* Define the SHA1 circular left shift macro */ +#define SHA1CircularShift(bits,word) \ + (((word) << (bits)) | ((word) >> (32-(bits)))) + +/* + * This function will initialize the SHA1Context in preparation for + * computing a new SHA1 message digest. + */ +static int SHA1Reset(SHA1Context *context) +{ + if (context == NULL) + return shaNull; + + context->Length_Low = 0; + context->Length_High = 0; + context->Message_Block_Index = 0; + + context->Intermediate_Hash[0] = 0x67452301; + context->Intermediate_Hash[1] = 0xEFCDAB89; + context->Intermediate_Hash[2] = 0x98BADCFE; + context->Intermediate_Hash[3] = 0x10325476; + context->Intermediate_Hash[4] = 0xC3D2E1F0; + + context->Computed = 0; + context->Corrupted = 0; + + return shaSuccess; +} + +/* + * This function will return the 160-bit message digest into the + * Message_Digest array provided by the caller. NOTE: The first octet + * of hash is stored in the 0th element, the last octet of hash in the + * 19th element. + */ +static int SHA1Result(SHA1Context *context, sha1_uint8_t Message_Digest[SHA1HashSize]) +{ + int i; + + if (context == NULL || Message_Digest == NULL) + return shaNull; + if (context->Corrupted) + return context->Corrupted; + + if (!context->Computed) { + SHA1PadMessage(context); + for (i = 0; i < 64; i++) { + /* message may be sensitive, clear it out */ + context->Message_Block[i] = 0; + } + context->Length_Low = 0; /* and clear length */ + context->Length_High = 0; + context->Computed = 1; + } + for (i = 0; i < SHA1HashSize; i++) + Message_Digest[i] = context->Intermediate_Hash[i>>2] >> 8 * (3 - (i & 0x03)); + + return shaSuccess; +} + +/* + * This function accepts an array of octets as the next portion of the + * message. + */ +static int SHA1Input(SHA1Context *context, const sha1_uint8_t *message_array, unsigned int length) +{ + if (length == 0) + return shaSuccess; + if (context == NULL || message_array == NULL) + return shaNull; + + if (context->Computed) { + context->Corrupted = shaStateError; + return shaStateError; + } + if (context->Corrupted) + return context->Corrupted; + while (length-- && !context->Corrupted) { + context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); + context->Length_Low += 8; + if (context->Length_Low == 0) { + context->Length_High++; + if (context->Length_High == 0) + context->Corrupted = 1; /* Message is too long */ + } + if (context->Message_Block_Index == 64) + SHA1ProcessMessageBlock(context); + message_array++; + } + + return shaSuccess; +} + +/* + * This function will process the next 512 bits of the message stored + * in the Message_Block array. NOTICE: Many of the variable names in + * this code, especially the single character names, were used because + * those were the names used in the publication. + */ +static void SHA1ProcessMessageBlock(SHA1Context *context) +{ + const sha1_uint32_t K[] = { /* Constants defined in SHA-1 */ + 0x5A827999, + 0x6ED9EBA1, + 0x8F1BBCDC, + 0xCA62C1D6 + }; + int t; /* Loop counter */ + sha1_uint32_t temp; /* Temporary word value */ + sha1_uint32_t W[80]; /* Word sequence */ + sha1_uint32_t A, B, C, D, E; /* Word buffers */ + + /* Initialize the first 16 words in the array W */ + for (t = 0; t < 16; t++) { + W[t] = context->Message_Block[t * 4 ] << 24; + W[t] |= context->Message_Block[t * 4 + 1] << 16; + W[t] |= context->Message_Block[t * 4 + 2] << 8; + W[t] |= context->Message_Block[t * 4 + 3]; + } + + for (t = 16; t < 80; t++) + W[t] = SHA1CircularShift(1, W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); + + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + + for (t = 0; t < 20; t++) { + temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + + for (t = 20; t < 40; t++) { + temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[1]; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + + for (t = 40; t < 60; t++) { + temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + + for (t = 60; t < 80; t++) { + temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[3]; + E = D; + D = C; + C = SHA1CircularShift(30, B); + B = A; + A = temp; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + + context->Message_Block_Index = 0; + + return; +} + +/* + * According to the standard, the message must be padded to an even + * 512 bits. The first padding bit must be a '1'. The last 64 bits + * represent the length of the original message. All bits in between + * should be 0. This function will pad the message according to those + * rules by filling the Message_Block array accordingly. It will also + * call the ProcessMessageBlock function provided appropriately. When + * it returns, it can be assumed that the message digest has been + * computed. + */ +static void SHA1PadMessage(SHA1Context *context) +{ + /* Check to see if the current message block is too small to hold + the initial padding bits and length. If so, we will pad the block, + process it, and then continue padding into a second block. */ + if (context->Message_Block_Index > 55) { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while (context->Message_Block_Index < 64) + context->Message_Block[context->Message_Block_Index++] = 0; + SHA1ProcessMessageBlock(context); + while(context->Message_Block_Index < 56) + context->Message_Block[context->Message_Block_Index++] = 0; + } + else { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 56) + context->Message_Block[context->Message_Block_Index++] = 0; + } + + /* Store the message length as the last 8 octets */ + context->Message_Block[56] = context->Length_High >> 24; + context->Message_Block[57] = context->Length_High >> 16; + context->Message_Block[58] = context->Length_High >> 8; + context->Message_Block[59] = context->Length_High; + context->Message_Block[60] = context->Length_Low >> 24; + context->Message_Block[61] = context->Length_Low >> 16; + context->Message_Block[62] = context->Length_Low >> 8; + context->Message_Block[63] = context->Length_Low; + + SHA1ProcessMessageBlock(context); + return; +} + +/* +** ==== END RFC 3174 CODE ==== +*/ + +struct sha1_st { + SHA1Context ctx; +}; + +sha1_rc_t sha1_create(sha1_t **sha1) +{ + if (sha1 == NULL) + return SHA1_RC_ARG; + if ((*sha1 = (sha1_t *)malloc(sizeof(sha1_t))) == NULL) + return SHA1_RC_MEM; + SHA1Reset(&((*sha1)->ctx)); + return SHA1_RC_OK; +} + +sha1_rc_t sha1_init(sha1_t *sha1) +{ + if (sha1 == NULL) + return SHA1_RC_ARG; + SHA1Reset(&(sha1->ctx)); + return SHA1_RC_OK; +} + +sha1_rc_t sha1_update(sha1_t *sha1, const void *data_ptr, size_t data_len) +{ + if (sha1 == NULL) + return SHA1_RC_ARG; + SHA1Input(&(sha1->ctx), (unsigned char *)data_ptr, (unsigned int)data_len); + return SHA1_RC_OK; +} + +sha1_rc_t sha1_store(sha1_t *sha1, void **data_ptr, size_t *data_len) +{ + SHA1Context ctx; + + if (sha1 == NULL || data_ptr == NULL) + return SHA1_RC_ARG; + if (*data_ptr == NULL) { + if ((*data_ptr = malloc(SHA1_LEN_BIN)) == NULL) + return SHA1_RC_MEM; + if (data_len != NULL) + *data_len = SHA1_LEN_BIN; + } + else { + if (data_len != NULL) { + if (*data_len < SHA1_LEN_BIN) + return SHA1_RC_MEM; + *data_len = SHA1_LEN_BIN; + } + } + memcpy((void *)(&ctx), (void *)(&(sha1->ctx)), sizeof(SHA1Context)); + SHA1Result(&(ctx), (unsigned char *)(*data_ptr)); + return SHA1_RC_OK; +} + +sha1_rc_t sha1_format(sha1_t *sha1, char **data_ptr, size_t *data_len) +{ + static const char hex[] = "0123456789abcdef"; + unsigned char buf[SHA1_LEN_BIN]; + unsigned char *bufptr; + size_t buflen; + sha1_rc_t rc; + int i; + + if (sha1 == NULL || data_ptr == NULL) + return SHA1_RC_ARG; + if (*data_ptr == NULL) { + if ((*data_ptr = (char *)malloc(SHA1_LEN_STR+1)) == NULL) + return SHA1_RC_MEM; + if (data_len != NULL) + *data_len = SHA1_LEN_STR+1; + } + else { + if (data_len != NULL) { + if (*data_len < SHA1_LEN_STR+1) + return SHA1_RC_MEM; + *data_len = SHA1_LEN_STR+1; + } + } + + bufptr = buf; + buflen = sizeof(buf); + if ((rc = sha1_store(sha1, (void **)((void *)&bufptr), &buflen)) != SHA1_RC_OK) + return rc; + + for (i = 0; i < (int)buflen; i++) { + (*data_ptr)[(i*2)+0] = hex[(int)(bufptr[i] >> 4)]; + (*data_ptr)[(i*2)+1] = hex[(int)(bufptr[i] & 0x0f)]; + } + (*data_ptr)[(i*2)] = '\0'; + return SHA1_RC_OK; +} + +sha1_rc_t sha1_destroy(sha1_t *sha1) +{ + if (sha1 == NULL) + return SHA1_RC_ARG; + free(sha1); + return SHA1_RC_OK; +} + Index: ossp-pkg/uuid/uuid_sha1.h RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_sha1.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_sha1.h,v' | diff -u /dev/null - -L'ossp-pkg/uuid/uuid_sha1.h' 2>/dev/null --- ossp-pkg/uuid/uuid_sha1.h +++ - 2024-05-21 07:38:03.596576187 +0200 @@ -0,0 +1,76 @@ +/* +** OSSP uuid - Universally Unique Identifier +** Copyright (c) 2004-2005 Ralf S. Engelschall +** Copyright (c) 2004-2005 The OSSP Project +** +** This file is part of OSSP uuid, a library for the generation +** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR +** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +** SUCH DAMAGE. +** +** uuid_sha1.h: SHA-1 API definition +*/ + +#ifndef __SHA1_H___ +#define __SHA1_H___ + +#include /* size_t */ + +#define SHA1_PREFIX uuid_ + +/* embedding support */ +#ifdef SHA1_PREFIX +#if defined(__STDC__) || defined(__cplusplus) +#define __SHA1_CONCAT(x,y) x ## y +#define SHA1_CONCAT(x,y) __SHA1_CONCAT(x,y) +#else +#define __SHA1_CONCAT(x) x +#define SHA1_CONCAT(x,y) __SHA1_CONCAT(x)y +#endif +#define sha1_st SHA1_CONCAT(SHA1_PREFIX,sha1_st) +#define sha1_t SHA1_CONCAT(SHA1_PREFIX,sha1_t) +#define sha1_create SHA1_CONCAT(SHA1_PREFIX,sha1_create) +#define sha1_init SHA1_CONCAT(SHA1_PREFIX,sha1_init) +#define sha1_update SHA1_CONCAT(SHA1_PREFIX,sha1_update) +#define sha1_store SHA1_CONCAT(SHA1_PREFIX,sha1_store) +#define sha1_format SHA1_CONCAT(SHA1_PREFIX,sha1_format) +#define sha1_destroy SHA1_CONCAT(SHA1_PREFIX,sha1_destroy) +#endif + +struct sha1_st; +typedef struct sha1_st sha1_t; + +#define SHA1_LEN_BIN 20 +#define SHA1_LEN_STR 40 + +typedef enum { + SHA1_RC_OK = 0, + SHA1_RC_ARG = 1, + SHA1_RC_MEM = 2 +} sha1_rc_t; + +extern sha1_rc_t sha1_create (sha1_t **sha1); +extern sha1_rc_t sha1_init (sha1_t *sha1); +extern sha1_rc_t sha1_update (sha1_t *sha1, const void *data_ptr, size_t data_len); +extern sha1_rc_t sha1_store (sha1_t *sha1, void **data_ptr, size_t *data_len); +extern sha1_rc_t sha1_format (sha1_t *sha1, char **data_ptr, size_t *data_len); +extern sha1_rc_t sha1_destroy (sha1_t *sha1); + +#endif /* __SHA1_H___ */ + Index: ossp-pkg/uuid/uuid_vers.h RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_vers.h,v rcsdiff -q -kk '-r1.13' '-r1.14' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_vers.h,v' 2>/dev/null --- uuid_vers.h 2005/01/13 10:37:36 1.13 +++ uuid_vers.h 2005/01/23 11:28:51 1.14 @@ -8,7 +8,7 @@ #ifndef _UUID_VERS_H_ #define _UUID_VERS_H_ -#define _UUID_VERSION 0x101202 +#define _UUID_VERSION 0x102200 typedef struct { const int v_hex; @@ -32,13 +32,13 @@ #undef _UUID_VERS_H_AS_HEADER_ _uuid_version_t _uuid_version = { - 0x101202, - "1.1.2", - "1.1.2 (13-Jan-2005)", - "This is OSSP uuid, Version 1.1.2 (13-Jan-2005)", - "OSSP uuid 1.1.2 (13-Jan-2005)", - "OSSP uuid/1.1.2", - "@(#)OSSP uuid 1.1.2 (13-Jan-2005)", + 0x102200, + "1.2.0", + "1.2.0 (23-Jan-2005)", + "This is OSSP uuid, Version 1.2.0 (23-Jan-2005)", + "OSSP uuid 1.2.0 (23-Jan-2005)", + "OSSP uuid/1.2.0", + "@(#)OSSP uuid 1.2.0 (23-Jan-2005)", "$Id$" };