hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cf_digest.h
Go to the documentation of this file.
1 /*
2  * Citrusleaf Foundation
3  * include/digest.h - message digests
4  *
5  * Copyright 2008 by Citrusleaf. All rights reserved.
6  * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE. THE COPYRIGHT NOTICE
7  * ABOVE DOES NOT EVIDENCE ANY ACTUAL OR INTENDED PUBLICATION.
8  */
9 
10 #pragma once
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <openssl/ripemd.h>
15 
16 /* SYNOPSIS
17  * Cryptographic message digests
18  * The intent is to provide an algorithm-neutral API for the computation of
19  * cryptographic digests of arbitrary bytes. Consequently, we define the
20  * cf_digest type to be an array of bytes of the appropriate length.
21  * The actual computation is done in one shot by calling cf_digest_compute().
22  */
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* cf_digest
29  * Storage for a message digest */
30 #define CF_DIGEST_KEY_SZ RIPEMD160_DIGEST_LENGTH
31 typedef struct { uint8_t digest[CF_DIGEST_KEY_SZ]; } cf_digest;
32 
33 void cf_digest_string(cf_digest *digest, char* output);
34 void cf_digest_dump(cf_digest *digest);
35 
36 /* cf_digest_compute
37  * Compute the digest of an input */
38 static inline void
39 cf_digest_compute(void *data, size_t len, cf_digest *d)
40 {
41  RIPEMD160((const unsigned char *) data, len, (unsigned char *) d->digest);
42 }
43 
44 
45 // Compute a digest
46 // the first value is the key data, the second is the set
47 // DO NOT USE THIS FUNCTION EXTERNALLY
48 // the externally visible function is 'citrusleaf_calculate_digest', which has
49 // the proper typing and swizzling
50 
51 static inline void
52 cf_digest_compute2(const void *data1, size_t len1, const void *data2, size_t len2, cf_digest *d)
53 {
54  if (len1 == 0) {
55  RIPEMD160((const unsigned char *) data2, len2, (unsigned char *) d->digest);
56  }
57  else {
58  RIPEMD160_CTX c;
59  RIPEMD160_Init(&c);
60  RIPEMD160_Update(&c, data1, len1);
61  RIPEMD160_Update(&c, data2, len2);
62  RIPEMD160_Final( (unsigned char *)(d->digest), &c);
63  }
64 }
65 
66 /* as_partition_getid
67  * A brief utility function to derive the partition ID from a digest */
68 
69 typedef uint16_t cl_partition_id;
70 static inline cl_partition_id
71 cl_partition_getid(uint32_t n_partitions, const cf_digest *d)
72 {
73  uint16_t *d_int = (uint16_t *)&d->digest[0];
74  cl_partition_id r = *d_int & (n_partitions - 1);
75  return(r);
76 }
77 
78 #ifdef __cplusplus
79 } // end extern "C"
80 #endif
81 
82