X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsha1.h;h=9015104f87eedd9dfad0deff1cf6b51f943bb388;hb=b5a36e3878937a489458f7a0ff42769e826ae88b;hp=75d3533da4be5e8b16c0f28aa7fb04b7031a6a1a;hpb=34e63086edddcae06d7c1a4fa84fec0861e50758;p=openvswitch diff --git a/lib/sha1.h b/lib/sha1.h index 75d3533d..9015104f 100644 --- a/lib/sha1.h +++ b/lib/sha1.h @@ -20,20 +20,21 @@ * limitations under the License. */ /* NIST Secure Hash Algorithm - * heavily modified by Uwe Hollerbach uh@alumni.caltech edu - * from Peter C. Gutmann's implementation as found in - * Applied Cryptography by Bruce Schneier - * This code is hereby placed in the public domain + * heavily modified by Uwe Hollerbach uh@alumni.caltech edu + * from Peter C. Gutmann's implementation as found in + * Applied Cryptography by Bruce Schneier + * This code is hereby placed in the public domain */ #ifndef SHA1_H #define SHA1_H +#include #include #include -/* Size of the SHA1 digest. */ -#define SHA1_DIGEST_SIZE 20 +#define SHA1_DIGEST_SIZE 20 /* Size of the SHA1 digest. */ +#define SHA1_HEX_DIGEST_LEN 40 /* Length of SHA1 digest as hex in ASCII. */ /* SHA1 context structure. */ struct sha1_ctx { @@ -48,4 +49,18 @@ void sha1_update(struct sha1_ctx *, const void *, size_t); void sha1_final(struct sha1_ctx *, uint8_t digest[SHA1_DIGEST_SIZE]); void sha1_bytes(const void *, size_t, uint8_t digest[SHA1_DIGEST_SIZE]); +#define SHA1_FMT \ + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" \ + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" +#define SHA1_ARGS(DIGEST) \ + ((DIGEST)[0]), ((DIGEST)[1]), ((DIGEST)[2]), ((DIGEST)[3]), \ + ((DIGEST)[4]), ((DIGEST)[5]), ((DIGEST)[6]), ((DIGEST)[7]), \ + ((DIGEST)[8]), ((DIGEST)[9]), ((DIGEST)[10]), ((DIGEST)[11]), \ + ((DIGEST)[12]), ((DIGEST)[13]), ((DIGEST)[14]), ((DIGEST)[15]), \ + ((DIGEST)[16]), ((DIGEST)[17]), ((DIGEST)[18]), ((DIGEST)[19]) + +void sha1_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], + char hex[SHA1_HEX_DIGEST_LEN + 1]); +bool sha1_from_hex(uint8_t digest[SHA1_DIGEST_SIZE], const char *hex); + #endif /* sha1.h */