X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsha1.c;h=cdccab3bfa6e52e5c623e1dfa1ff8c04178dffc3;hb=fe13b0e71752a5eb30b21e7a09d2f9370bc02387;hp=f73f2d6477e28e32ceed79f2e57e78544bd6190e;hpb=5eccf359391f7fe2cdb0edbaaf5680895c115218;p=openvswitch diff --git a/lib/sha1.c b/lib/sha1.c index f73f2d64..cdccab3b 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -1,7 +1,7 @@ /* * This file is from the Apache Portable Runtime Library. * The full upstream copyright and license statement is included below. - * Modifications copyright (c) 2009 Nicira Networks. + * Modifications copyright (c) 2009, 2010 Nicira Networks. */ /* Licensed to the Apache Software Foundation (ASF) under one or more @@ -31,7 +31,10 @@ #include #include "sha1.h" +#include #include +#include "compiler.h" +#include "util.h" /* a bit faster & bigger, if defined */ #define UNROLL_LOOPS @@ -148,12 +151,12 @@ sha_transform(struct sha1_ctx *sha_info) /* 'count' is the number of bytes to do an endian flip. */ static void -maybe_byte_reverse(uint32_t *buffer, int count) +maybe_byte_reverse(uint32_t *buffer OVS_UNUSED, int count OVS_UNUSED) { +#if !WORDS_BIGENDIAN int i; uint8_t ct[4], *cp; -#if !WORDS_BIGENDIAN count /= sizeof(uint32_t); cp = (uint8_t *) buffer; for (i = 0; i < count; i++) { @@ -279,3 +282,34 @@ sha1_bytes(const void *data, size_t n, uint8_t digest[SHA1_DIGEST_SIZE]) sha1_update(&ctx, data, n); sha1_final(&ctx, digest); } + +void +sha1_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], + char hex[SHA1_HEX_DIGEST_LEN + 1]) +{ + int i; + + for (i = 0; i < SHA1_DIGEST_SIZE; i++) { + *hex++ = "0123456789abcdef"[digest[i] >> 4]; + *hex++ = "0123456789abcdef"[digest[i] & 15]; + } + *hex = '\0'; +} + +bool +sha1_from_hex(uint8_t digest[SHA1_DIGEST_SIZE], const char *hex) +{ + int i; + + for (i = 0; i < SHA1_DIGEST_SIZE; i++) { + bool ok; + + digest[i] = hexits_value(hex, 2, &ok); + if (!ok) { + return false; + } + hex += 2; + } + return true; +} +