Guardtime KSI c SDK
hash.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2015 Guardtime, Inc.
3  *
4  * This file is part of the Guardtime client SDK.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License").
7  * You may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES, CONDITIONS, OR OTHER LICENSES OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  * "Guardtime" and "KSI" are trademarks or registered trademarks of
16  * Guardtime, Inc., and no license to trademarks is granted; Guardtime
17  * reserves and retains all trademark rights.
18  */
19 
20 #ifndef KSI_HASH_H_
21 #define KSI_HASH_H_
22 
23 #include <time.h>
24 
25 #include "types_base.h"
26 #include "common.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
46  typedef struct KSI_DataHasher_st KSI_DataHasher;
47 
52  typedef struct KSI_DataHash_st KSI_DataHash;
53 
58  typedef enum KSI_HashAlgorithm_en {
61 
82 
83  /* Number of known hash algorithms. */
86 
87  KSI_VAR_DEPRECATED(extern const int KSI_HASHALG_SHA3_244, This is a typo - use #KSI_HASHALG_SHA3_224 instead!);
88 
92  #define KSI_MAX_IMPRINT_LEN 65 /* Algorithm ID (1 byte) + longest digest. */
93 
107  int KSI_DataHasher_open(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHasher **hasher);
108 
117 
128  int KSI_DataHasher_add(KSI_DataHasher *hasher, const void *data, size_t data_length);
129 
136  int KSI_DataHasher_addImprint(KSI_DataHasher *hasher, const KSI_DataHash *hsh);
137 
145 
154  int KSI_DataHasher_close(KSI_DataHasher *hasher, KSI_DataHash **hash);
155 
162  void KSI_DataHasher_free(KSI_DataHasher *hasher);
163 
171  void KSI_DataHash_free(KSI_DataHash *hash);
172 
187  int KSI_DataHash_create(KSI_CTX *ctx, const void *data, size_t data_length, KSI_HashAlgorithm algo_id, KSI_DataHash **hash);
188 
198 
215  int KSI_DataHash_extract(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id, const unsigned char **digest, size_t *digest_length);
216 
231  int KSI_DataHash_fromDigest(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, const unsigned char *digest, size_t digest_length, KSI_DataHash **hash);
232 
242  int KSI_DataHash_getImprint(const KSI_DataHash *hash, const unsigned char **imprint, size_t *imprint_length);
243 
257  int KSI_DataHash_fromImprint(KSI_CTX *ctx, const unsigned char *imprint, size_t imprint_length, KSI_DataHash **hash);
258 
276 
285  unsigned int KSI_getHashLength(KSI_HashAlgorithm algo_id);
286 
294 
302 
310 
326 
337  int KSI_checkHashAlgorithmAt(KSI_HashAlgorithm algo_id, time_t used_at);
338 
348 
357  const char *KSI_getHashAlgorithmName(KSI_HashAlgorithm algo_id);
358 
368  int KSI_DataHash_equals(const KSI_DataHash *left, const KSI_DataHash *right);
369 
372 
379  int KSI_DataHash_getHashAlg(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id);
380 
388  char *KSI_DataHash_toString(const KSI_DataHash *hsh, char *buf, size_t buf_len);
389 
398 
401 #define KSI_DataHashList_append(lst, o) KSI_APPLY_TO_NOT_NULL((lst), append, ((lst), (o)))
402 #define KSI_DataHashList_remove(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), removeElement, ((lst), (pos), (o)))
403 #define KSI_DataHashList_indexOf(lst, o, i) KSI_APPLY_TO_NOT_NULL((lst), indexOf, ((lst), (o), (i)))
404 #define KSI_DataHashList_insertAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), insertAt, ((lst), (pos), (o)))
405 #define KSI_DataHashList_replaceAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), replaceAt, ((lst), (pos), (o)))
406 #define KSI_DataHashList_elementAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), elementAt, ((lst), (pos), (o)))
407 #define KSI_DataHashList_length(lst) (((lst) != NULL && (lst)->length != NULL) ? (lst)->length((lst)) : 0)
408 #define KSI_DataHashList_sort(lst, cmp) KSI_APPLY_TO_NOT_NULL((lst), sort, ((lst), (cmp)))
409 #define KSI_DataHashList_foldl(lst, foldCtx, foldFn) (((lst) != NULL) ? (((lst)->foldl != NULL) ? ((lst)->foldl((lst), (foldCtx), (foldFn))) : KSI_INVALID_STATE) : KSI_OK)
410 
414 #ifdef __cplusplus
415 }
416 #endif
417 
418 #endif /* KSI_HASH_H_ */
int KSI_checkHashAlgorithmAt(KSI_HashAlgorithm algo_id, time_t used_at)
#define KSI_DEFINE_FN_TO_TLV(typ)
Definition: types_base.h:41
unsigned int KSI_HashAlgorithm_getBlockSize(KSI_HashAlgorithm algo_id)
KSI_DataHash * KSI_DataHash_ref(KSI_DataHash *o)
int KSI_DataHasher_reset(KSI_DataHasher *hasher)
Definition: hash.h:81
Definition: hash.h:77
Definition: hash.h:71
time_t KSI_HashAlgorithm_getObsoleteFrom(KSI_HashAlgorithm algo_id)
void KSI_DataHasher_free(KSI_DataHasher *hasher)
int KSI_DataHash_equals(const KSI_DataHash *left, const KSI_DataHash *right)
Definition: hash.h:84
time_t KSI_HashAlgorithm_getDeprecatedFrom(KSI_HashAlgorithm algo_id)
int KSI_DataHash_extract(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id, const unsigned char **digest, size_t *digest_length)
int KSI_DataHasher_add(KSI_DataHasher *hasher, const void *data, size_t data_length)
int KSI_DataHash_fromImprint(KSI_CTX *ctx, const unsigned char *imprint, size_t imprint_length, KSI_DataHash **hash)
int KSI_DataHash_create(KSI_CTX *ctx, const void *data, size_t data_length, KSI_HashAlgorithm algo_id, KSI_DataHash **hash)
#define KSI_DEFINE_FN_FROM_TLV(typ)
Definition: types_base.h:30
int KSI_DataHasher_close(KSI_DataHasher *hasher, KSI_DataHash **hash)
const char * KSI_getHashAlgorithmName(KSI_HashAlgorithm algo_id)
Definition: hash.h:79
#define KSI_DEFINE_REF(typ)
Definition: types_base.h:56
struct KSI_DataHash_st KSI_DataHash
Definition: hash.h:52
int KSI_isHashAlgorithmTrusted(KSI_HashAlgorithm algo_id)
int KSI_DataHasher_addImprint(KSI_DataHasher *hasher, const KSI_DataHash *hsh)
Definition: hash.h:69
Definition: hash.h:73
Definition: hash.h:75
enum KSI_HashAlgorithm_en KSI_HashAlgorithm
Definition: hash.h:67
#define KSI_FN_DEPRECATED(decl, comment)
Definition: common.h:50
Definition: hash.h:65
int KSI_DataHash_fromDigest(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, const unsigned char *digest, size_t digest_length, KSI_DataHash **hash)
KSI_HashAlgorithm KSI_getHashAlgorithmByName(const char *name)
char * KSI_DataHash_toString(const KSI_DataHash *hsh, char *buf, size_t buf_len)
struct KSI_OctetString_st KSI_OctetString
Definition: types_base.h:145
Definition: hash.h:60
void KSI_DataHash_free(KSI_DataHash *hash)
KSI_HashAlgorithm_en
Definition: hash.h:58
#define KSI_VAR_DEPRECATED(decl, comment)
Definition: common.h:66
#define KSI_DEFINE_LIST(type)
Definition: list.h:146
int KSI_DataHash_getImprint(const KSI_DataHash *hash, const unsigned char **imprint, size_t *imprint_length)
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
int KSI_DataHasher_addOctetString(KSI_DataHasher *hasher, const KSI_OctetString *data)
const int KSI_HASHALG_SHA3_244
struct KSI_DataHasher_st KSI_DataHasher
Definition: hash.h:46
int KSI_DataHash_getHashAlg(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id)
Definition: hash.h:63
int KSI_DataHash_createZero(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHash **hsh)
unsigned int KSI_getHashLength(KSI_HashAlgorithm algo_id)
int KSI_isHashAlgorithmSupported(KSI_HashAlgorithm algo_id)
int KSI_DataHasher_open(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHasher **hasher)
int KSI_DataHash_clone(KSI_DataHash *from, KSI_DataHash **to)