From 00476268870b01938800af9a5ca776695df13f5d Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Tue, 5 Sep 2017 11:19:26 +0200 Subject: libuuid: add support for hash-based UUIDs Adding V3 and V5 UUIDs per RFC-4122. [kzak@redhat.com: - fix symbols file] Signed-off-by: Philip Prindeville Signed-off-by: Karel Zak --- include/Makemodule.am | 1 + include/sha1.h | 46 ++++++ lib/Makemodule.am | 3 +- lib/sha1.c | 296 ++++++++++++++++++++++++++++++++++++ libuuid/src/Makemodule.am | 5 +- libuuid/src/gen_uuid.c | 56 +++++++ libuuid/src/libuuid.sym | 11 +- libuuid/src/predefined.c | 80 ++++++++++ libuuid/src/uuid.h | 15 ++ tests/commands.sh | 2 + tests/expected/sha1/sha1 | 7 + tests/expected/uuid/namespace | 7 + tests/helpers/Makemodule.am | 7 + tests/helpers/test_sha1.c | 29 ++++ tests/helpers/test_uuid_namespace.c | 37 +++++ tests/ts/sha1/data | 7 + tests/ts/sha1/sha1 | 31 ++++ tests/ts/uuid/namespace | 29 ++++ 18 files changed, 666 insertions(+), 3 deletions(-) create mode 100644 include/sha1.h create mode 100644 lib/sha1.c create mode 100644 libuuid/src/predefined.c create mode 100644 tests/expected/sha1/sha1 create mode 100644 tests/expected/uuid/namespace create mode 100644 tests/helpers/test_sha1.c create mode 100644 tests/helpers/test_uuid_namespace.c create mode 100644 tests/ts/sha1/data create mode 100755 tests/ts/sha1/sha1 create mode 100755 tests/ts/uuid/namespace diff --git a/include/Makemodule.am b/include/Makemodule.am index e9b1e3021..bed548908 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -45,6 +45,7 @@ dist_noinst_HEADERS += \ include/pt-sun.h \ include/randutils.h \ include/rpmatch.h \ + include/sha1.h \ include/setproctitle.h \ include/statfs_magic.h \ include/strutils.h \ diff --git a/include/sha1.h b/include/sha1.h new file mode 100644 index 000000000..5c28bce92 --- /dev/null +++ b/include/sha1.h @@ -0,0 +1,46 @@ +#ifndef SHA1_H +#define SHA1_H + +/* + SHA-1 in C + By Steve Reid + 100% Public Domain + */ + +#include "stdint.h" + +#define SHA1LENGTH 20 + +typedef struct +{ + uint32_t state[5]; + uint32_t count[2]; + unsigned char buffer[64]; +} SHA1_CTX; + +void SHA1Transform( + uint32_t state[5], + const unsigned char buffer[64] + ); + +void SHA1Init( + SHA1_CTX * context + ); + +void SHA1Update( + SHA1_CTX * context, + const unsigned char *data, + uint32_t len + ); + +void SHA1Final( + unsigned char digest[SHA1LENGTH], + SHA1_CTX * context + ); + +void SHA1( + char *hash_out, + const char *str, + unsigned len); + +#endif /* SHA1_H */ diff --git a/lib/Makemodule.am b/lib/Makemodule.am index 82fefbaaa..73ac9a6f5 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -24,7 +24,8 @@ libcommon_la_SOURCES = \ lib/timeutils.c \ lib/ttyutils.c \ lib/exec_shell.c \ - lib/strv.c + lib/strv.c \ + lib/sha1.c if LINUX libcommon_la_SOURCES += \ diff --git a/lib/sha1.c b/lib/sha1.c new file mode 100644 index 000000000..a2ac7f8ef --- /dev/null +++ b/lib/sha1.c @@ -0,0 +1,296 @@ +/* +SHA-1 in C +By Steve Reid +100% Public Domain + +Test Vectors (from FIPS PUB 180-1) +"abc" + A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D +"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 +A million repetitions of "a" + 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F +*/ + +/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */ +/* #define SHA1HANDSOFF * Copies data before messing with it. */ + +#define SHA1HANDSOFF + +#include +#include + +/* for uint32_t */ +#include + +#include "sha1.h" + + +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + +/* blk0() and blk() perform the initial expand. */ +/* I got the idea of expanding during the round function from SSLeay */ +#if BYTE_ORDER == LITTLE_ENDIAN +#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ + |(rol(block->l[i],8)&0x00FF00FF)) +#elif BYTE_ORDER == BIG_ENDIAN +#define blk0(i) block->l[i] +#else +#error "Endianness not defined!" +#endif +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ + ^block->l[(i+2)&15]^block->l[i&15],1)) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); + + +/* Hash a single 512-bit block. This is the core of the algorithm. */ + +void SHA1Transform( + uint32_t state[5], + const unsigned char buffer[64] +) +{ + uint32_t a, b, c, d, e; + + typedef union + { + unsigned char c[64]; + uint32_t l[16]; + } CHAR64LONG16; + +#ifdef SHA1HANDSOFF + CHAR64LONG16 block[1]; /* use array to appear as a pointer */ + + memcpy(block, buffer, 64); +#else + /* The following had better never be used because it causes the + * pointer-to-const buffer to be cast into a pointer to non-const. + * And the result is written through. I threw a "const" in, hoping + * this will cause a diagnostic. + */ + CHAR64LONG16 *block = (const CHAR64LONG16 *) buffer; +#endif + /* Copy context->state[] to working vars */ + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + /* 4 rounds of 20 operations each. Loop unrolled. */ + R0(a, b, c, d, e, 0); + R0(e, a, b, c, d, 1); + R0(d, e, a, b, c, 2); + R0(c, d, e, a, b, 3); + R0(b, c, d, e, a, 4); + R0(a, b, c, d, e, 5); + R0(e, a, b, c, d, 6); + R0(d, e, a, b, c, 7); + R0(c, d, e, a, b, 8); + R0(b, c, d, e, a, 9); + R0(a, b, c, d, e, 10); + R0(e, a, b, c, d, 11); + R0(d, e, a, b, c, 12); + R0(c, d, e, a, b, 13); + R0(b, c, d, e, a, 14); + R0(a, b, c, d, e, 15); + R1(e, a, b, c, d, 16); + R1(d, e, a, b, c, 17); + R1(c, d, e, a, b, 18); + R1(b, c, d, e, a, 19); + R2(a, b, c, d, e, 20); + R2(e, a, b, c, d, 21); + R2(d, e, a, b, c, 22); + R2(c, d, e, a, b, 23); + R2(b, c, d, e, a, 24); + R2(a, b, c, d, e, 25); + R2(e, a, b, c, d, 26); + R2(d, e, a, b, c, 27); + R2(c, d, e, a, b, 28); + R2(b, c, d, e, a, 29); + R2(a, b, c, d, e, 30); + R2(e, a, b, c, d, 31); + R2(d, e, a, b, c, 32); + R2(c, d, e, a, b, 33); + R2(b, c, d, e, a, 34); + R2(a, b, c, d, e, 35); + R2(e, a, b, c, d, 36); + R2(d, e, a, b, c, 37); + R2(c, d, e, a, b, 38); + R2(b, c, d, e, a, 39); + R3(a, b, c, d, e, 40); + R3(e, a, b, c, d, 41); + R3(d, e, a, b, c, 42); + R3(c, d, e, a, b, 43); + R3(b, c, d, e, a, 44); + R3(a, b, c, d, e, 45); + R3(e, a, b, c, d, 46); + R3(d, e, a, b, c, 47); + R3(c, d, e, a, b, 48); + R3(b, c, d, e, a, 49); + R3(a, b, c, d, e, 50); + R3(e, a, b, c, d, 51); + R3(d, e, a, b, c, 52); + R3(c, d, e, a, b, 53); + R3(b, c, d, e, a, 54); + R3(a, b, c, d, e, 55); + R3(e, a, b, c, d, 56); + R3(d, e, a, b, c, 57); + R3(c, d, e, a, b, 58); + R3(b, c, d, e, a, 59); + R4(a, b, c, d, e, 60); + R4(e, a, b, c, d, 61); + R4(d, e, a, b, c, 62); + R4(c, d, e, a, b, 63); + R4(b, c, d, e, a, 64); + R4(a, b, c, d, e, 65); + R4(e, a, b, c, d, 66); + R4(d, e, a, b, c, 67); + R4(c, d, e, a, b, 68); + R4(b, c, d, e, a, 69); + R4(a, b, c, d, e, 70); + R4(e, a, b, c, d, 71); + R4(d, e, a, b, c, 72); + R4(c, d, e, a, b, 73); + R4(b, c, d, e, a, 74); + R4(a, b, c, d, e, 75); + R4(e, a, b, c, d, 76); + R4(d, e, a, b, c, 77); + R4(c, d, e, a, b, 78); + R4(b, c, d, e, a, 79); + /* Add the working vars back into context.state[] */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + /* Wipe variables */ + a = b = c = d = e = 0; +#ifdef SHA1HANDSOFF + memset(block, '\0', sizeof(block)); +#endif +} + + +/* SHA1Init - Initialize new context */ + +void SHA1Init( + SHA1_CTX * context +) +{ + /* SHA1 initialization constants */ + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; + context->state[4] = 0xC3D2E1F0; + context->count[0] = context->count[1] = 0; +} + + +/* Run your data through this. */ + +void SHA1Update( + SHA1_CTX * context, + const unsigned char *data, + uint32_t len +) +{ + uint32_t i; + + uint32_t j; + + j = context->count[0]; + if ((context->count[0] += len << 3) < j) + context->count[1]++; + context->count[1] += (len >> 29); + j = (j >> 3) & 63; + if ((j + len) > 63) + { + memcpy(&context->buffer[j], data, (i = 64 - j)); + SHA1Transform(context->state, context->buffer); + for (; i + 63 < len; i += 64) + { + SHA1Transform(context->state, &data[i]); + } + j = 0; + } + else + i = 0; + memcpy(&context->buffer[j], &data[i], len - i); +} + + +/* Add padding and return the message digest. */ + +void SHA1Final( + unsigned char digest[20], + SHA1_CTX * context +) +{ + unsigned i; + + unsigned char finalcount[8]; + + unsigned char c; + +#if 0 /* untested "improvement" by DHR */ + /* Convert context->count to a sequence of bytes + * in finalcount. Second element first, but + * big-endian order within element. + * But we do it all backwards. + */ + unsigned char *fcp = &finalcount[8]; + + for (i = 0; i < 2; i++) + { + uint32_t t = context->count[i]; + + int j; + + for (j = 0; j < 4; t >>= 8, j++) + *--fcp = (unsigned char) t} +#else + for (i = 0; i < 8; i++) + { + finalcount[i] = (unsigned char) ((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ + } +#endif + c = 0200; + SHA1Update(context, &c, 1); + while ((context->count[0] & 504) != 448) + { + c = 0000; + SHA1Update(context, &c, 1); + } + SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ + for (i = 0; i < 20; i++) + { + digest[i] = (unsigned char) + ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); + } + /* Wipe variables */ + memset(context, '\0', sizeof(*context)); + memset(&finalcount, '\0', sizeof(finalcount)); +} + +void SHA1( + char *hash_out, + const char *str, + unsigned len) +{ + SHA1_CTX ctx; + unsigned int ii; + + SHA1Init(&ctx); + for (ii=0; ii + * Copyright (C) 2011-2017 Kareil Zak */ UUID_1.0 { global: @@ -34,6 +34,15 @@ global: uuid_generate_time_safe; } UUID_1.0; +/* + * version(s) since util-linux.2.31 + */ +UUID_2.31 { +global: + uuid_generate_md5; + uuid_generate_sha1; + uuid_get_template; +} UUID_2.20; /* * __uuid_* this is not part of the official API, this is diff --git a/libuuid/src/predefined.c b/libuuid/src/predefined.c new file mode 100644 index 000000000..0be90ca04 --- /dev/null +++ b/libuuid/src/predefined.c @@ -0,0 +1,80 @@ +/* + * predefined.c --- well-known UUIDs from the RFC-4122 namespace + * + * Copyright (C) 2017 Philip Prindeville + * + * %Begin-Header% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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 NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * %End-Header% + */ + +#include +#include "uuid.h" + +/* + * These are time-based UUIDs that are well-known in that they've + * been canonized as part of RFC-4122, Appendex C. They are to + * be used as the namespace (ns) argument to the uuid_generate_md5() + * and uuid_generate_sha1() functions. + * + * See Section 4.3 for the particulars of how namespace UUIDs + * are combined with seed values to generate new UUIDs. + */ + +UUID_DEFINE(NameSpace_DNS, + 0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); + +UUID_DEFINE(NameSpace_URL, + 0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); + +UUID_DEFINE(NameSpace_OID, + 0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1, + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); + +UUID_DEFINE(NameSpace_X500, + 0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); + +const uuid_t *uuid_get_template(const char *alias) +{ + if (!alias || !*alias) + return NULL; + + if (!strcmp(alias, "dns")) + return &NameSpace_DNS; + else if (!strcmp(alias, "url")) + return &NameSpace_URL; + else if (!strcmp(alias, "oid")) + return &NameSpace_OID; + else if (!strcmp(alias, "x500") || !strcmp(alias, "x.500")) + return &NameSpace_X500; + else + return NULL; +} + diff --git a/libuuid/src/uuid.h b/libuuid/src/uuid.h index 30bd4c0e0..bf4e50063 100644 --- a/libuuid/src/uuid.h +++ b/libuuid/src/uuid.h @@ -49,9 +49,18 @@ typedef unsigned char uuid_t[16]; #define UUID_VARIANT_MICROSOFT 2 #define UUID_VARIANT_OTHER 3 +#define UUID_VARIANT_SHIFT 5 +#define UUID_VARIANT_MASK 0x7 + /* UUID Type definitions */ #define UUID_TYPE_DCE_TIME 1 +#define UUID_TYPE_DCE_SECURITY 2 +#define UUID_TYPE_DCE_MD5 3 #define UUID_TYPE_DCE_RANDOM 4 +#define UUID_TYPE_DCE_SHA1 5 + +#define UUID_TYPE_SHIFT 4 +#define UUID_TYPE_MASK 0xf /* Allow UUID constants to be defined */ #ifdef __GNUC__ @@ -81,6 +90,9 @@ extern void uuid_generate_random(uuid_t out); extern void uuid_generate_time(uuid_t out); extern int uuid_generate_time_safe(uuid_t out); +extern void uuid_generate_md5(uuid_t out, const uuid_t ns, const char *name, size_t len); +extern void uuid_generate_sha1(uuid_t out, const uuid_t ns, const char *name, size_t len); + /* isnull.c */ extern int uuid_is_null(const uuid_t uu); @@ -97,6 +109,9 @@ extern time_t uuid_time(const uuid_t uu, struct timeval *ret_tv); extern int uuid_type(const uuid_t uu); extern int uuid_variant(const uuid_t uu); +/* predefined.c */ +extern const uuid_t *uuid_get_template(const char *alias); + #ifdef __cplusplus } #endif diff --git a/tests/commands.sh b/tests/commands.sh index efa0278c1..655344102 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -26,6 +26,7 @@ TS_HELPER_PYLIBMOUNT_UPDATE="$top_srcdir/libmount/python/test_mount_tab_update.p TS_HELPER_LOGGER="$top_builddir/test_logger" TS_HELPER_LOGINDEFS="$top_builddir/test_logindefs" TS_HELPER_MD5="$top_builddir/test_md5" +TS_HELPER_SHA1="$top_builddir/test_sha1" TS_HELPER_MKFS_MINIX="$top_builddir/test_mkfs_minix" TS_HELPER_MORE=${TS_HELPER_MORE-"$top_builddir/test_more"} TS_HELPER_PARTITIONS="$top_builddir/sample-partitions" @@ -36,6 +37,7 @@ TS_HELPER_STRUTILS="$top_builddir/test_strutils" TS_HELPER_SYSINFO="$top_builddir/test_sysinfo" TS_HELPER_TIOCSTI="$top_builddir/test_tiocsti" TS_HELPER_UUID_PARSER="$top_builddir/test_uuid_parser" +TS_HELPER_UUID_NAMESPACE="$top_builddir/test_uuid_namespace" # paths to commands TS_CMD_ADDPART=${TS_CMD_ADDPART:-"$top_builddir/addpart"} diff --git a/tests/expected/sha1/sha1 b/tests/expected/sha1/sha1 new file mode 100644 index 000000000..35c72861c --- /dev/null +++ b/tests/expected/sha1/sha1 @@ -0,0 +1,7 @@ +da39a3ee5e6b4b0d3255bfef95601890afd80709 +a9993e364706816aba3e25717850c26c9cd0d89d +da3175a32e6c1aacfd3d3f35770188ae0ab6d078 +7496226c17d4d0a770cea72eebb659c16753b956 +db50ea8b1b20567cd4d8a7fa14de8d37ce9b722c +90e072e1df8de879ca307610d5ced675af55a4ac +2eda696c8df17722d80518bebb33742e311a4ac1 diff --git a/tests/expected/uuid/namespace b/tests/expected/uuid/namespace new file mode 100644 index 000000000..78609759e --- /dev/null +++ b/tests/expected/uuid/namespace @@ -0,0 +1,7 @@ +uuid_get_template dns returns 6ba7b810-9dad-11d1-80b4-00c04fd430c8 +uuid_get_template url returns 6ba7b811-9dad-11d1-80b4-00c04fd430c8 +uuid_get_template oid returns 6ba7b812-9dad-11d1-80b4-00c04fd430c8 +uuid_get_template x500 returns 6ba7b814-9dad-11d1-80b4-00c04fd430c8 +uuid_get_template NULL returns NULL +uuid_get_template returns NULL +uuid_get_template unknown returns NULL diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am index 3070a8bbc..2f2611b67 100644 --- a/tests/helpers/Makemodule.am +++ b/tests/helpers/Makemodule.am @@ -5,6 +5,9 @@ test_byteswap_SOURCES = tests/helpers/test_byteswap.c check_PROGRAMS += test_md5 test_md5_SOURCES = tests/helpers/test_md5.c lib/md5.c +check_PROGRAMS += test_sha1 +test_sha1_SOURCES = tests/helpers/test_sha1.c lib/sha1.c + check_PROGRAMS += test_pathnames test_pathnames_SOURCES = tests/helpers/test_pathnames.c @@ -18,3 +21,7 @@ test_sigreceive_LDADD = $(LDADD) libcommon.la check_PROGRAMS += test_tiocsti test_tiocsti_SOURCES = tests/helpers/test_tiocsti.c +check_PROGRAMS += test_uuid_namespace +test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \ + libuuid/src/predefined.c libuuid/src/unpack.c libuuid/src/unparse.c + diff --git a/tests/helpers/test_sha1.c b/tests/helpers/test_sha1.c new file mode 100644 index 000000000..5a1972935 --- /dev/null +++ b/tests/helpers/test_sha1.c @@ -0,0 +1,29 @@ + +#include +#include + +#include "sha1.h" + +int main(void) +{ + int i, ret; + SHA1_CTX ctx; + unsigned char digest[SHA1LENGTH]; + unsigned char buf[BUFSIZ]; + + SHA1Init( &ctx ); + + while(!feof(stdin) && !ferror(stdin)) { + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret) + SHA1Update( &ctx, buf, ret ); + } + + fclose(stdin); + SHA1Final( digest, &ctx ); + + for (i = 0; i < SHA1LENGTH; i++) + printf( "%02x", digest[i] ); + printf("\n"); + return 0; +} diff --git a/tests/helpers/test_uuid_namespace.c b/tests/helpers/test_uuid_namespace.c new file mode 100644 index 000000000..1bbf8754d --- /dev/null +++ b/tests/helpers/test_uuid_namespace.c @@ -0,0 +1,37 @@ +#include +#include +#include + +#include "../libuuid/src/uuid.h" + +static void get_template(const char *ns) +{ + const uuid_t *uuidptr; + char buf[37]; + + uuidptr = uuid_get_template(ns); + if (uuidptr == NULL) + strcpy(buf, "NULL"); + else + uuid_unparse_lower(*uuidptr, buf); + + printf("uuid_get_template %s returns %s\n", (ns ? ns : "NULL"), buf); +} + +int main(void) +{ + get_template("dns"); + + get_template("url"); + + get_template("oid"); + + get_template("x500"); + + get_template(NULL); + get_template(""); + get_template("unknown"); + + exit(0); +} + diff --git a/tests/ts/sha1/data b/tests/ts/sha1/data new file mode 100644 index 000000000..1eed05a0b --- /dev/null +++ b/tests/ts/sha1/data @@ -0,0 +1,7 @@ + +abc +qazxswedc +1qazxsw23edc +a a a a a a a a a a +KUWIOJDNWQKLFDHQUWEDAYCNAUIWSYDUQUICBSKLBCLUWIGDF +EASC6545642432132SDECSESCEACSJKDWIOUDOIWIDOQPWUDQWIOSNXCSASCA diff --git a/tests/ts/sha1/sha1 b/tests/ts/sha1/sha1 new file mode 100755 index 000000000..055d690a1 --- /dev/null +++ b/tests/ts/sha1/sha1 @@ -0,0 +1,31 @@ +#!/bin/bash + +# +# Copyright (C) 2009 Karel Zak +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_HELPER_SHA1" + +cat $TS_SELF/data | while read data +do + echo -n $data | $TS_HELPER_SHA1 >> $TS_OUTPUT +done + +ts_finalize + diff --git a/tests/ts/uuid/namespace b/tests/ts/uuid/namespace new file mode 100755 index 000000000..bec2c9d69 --- /dev/null +++ b/tests/ts/uuid/namespace @@ -0,0 +1,29 @@ +#!/bin/bash + +# +# Copyright (C) 2009 Karel Zak +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_HELPER_UUID_NAMESPACE" + +$TS_HELPER_UUID_NAMESPACE > $TS_OUTPUT + +ts_finalize + + -- cgit v1.2.3-55-g7522