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 
55 
60  typedef enum KSI_HashAlgorithm_en {
82 
83  /* Number of known hash algorithms. */
85 
89 
90  KSI_VAR_DEPRECATED(extern const int KSI_HASHALG_SHA3_244, This is a typo - use #KSI_HASHALG_SHA3_224 instead!);
91 
95  #define KSI_MAX_IMPRINT_LEN 65 /* Algorithm ID (1 byte) + longest digest. */
96 
111 
120 
131  int KSI_DataHasher_add(KSI_DataHasher *hasher, const void *data, size_t data_length);
132 
140 
148 
158 
166 
175 
190  int KSI_DataHash_create(KSI_CTX *ctx, const void *data, size_t data_length, KSI_HashAlgorithm algo_id, KSI_DataHash **hash);
191 
201 
218  int KSI_DataHash_extract(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id, const unsigned char **digest, size_t *digest_length);
219 
234  int KSI_DataHash_fromDigest(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, const unsigned char *digest, size_t digest_length, KSI_DataHash **hash);
235 
245  int KSI_DataHash_getImprint(const KSI_DataHash *hash, const unsigned char **imprint, size_t *imprint_length);
246 
260  int KSI_DataHash_fromImprint(KSI_CTX *ctx, const unsigned char *imprint, size_t imprint_length, KSI_DataHash **hash);
261 
280 
289  unsigned int KSI_getHashLength(KSI_HashAlgorithm algo_id);
290 
298 
306 
314 
330 
341  int KSI_checkHashAlgorithmAt(KSI_HashAlgorithm algo_id, time_t used_at);
342 
352 
362 
372  int KSI_DataHash_equals(const KSI_DataHash *left, const KSI_DataHash *right);
373 
376 
384 
392  char *KSI_DataHash_toString(const KSI_DataHash *hsh, char *buf, size_t buf_len);
393 
402 
405 #define KSI_DataHashList_append(lst, o) KSI_APPLY_TO_NOT_NULL((lst), append, ((lst), (o)))
406 #define KSI_DataHashList_remove(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), removeElement, ((lst), (pos), (o)))
407 #define KSI_DataHashList_indexOf(lst, o, i) KSI_APPLY_TO_NOT_NULL((lst), indexOf, ((lst), (o), (i)))
408 #define KSI_DataHashList_insertAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), insertAt, ((lst), (pos), (o)))
409 #define KSI_DataHashList_replaceAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), replaceAt, ((lst), (pos), (o)))
410 #define KSI_DataHashList_elementAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), elementAt, ((lst), (pos), (o)))
411 #define KSI_DataHashList_length(lst) (((lst) != NULL && (lst)->length != NULL) ? (lst)->length((lst)) : 0)
412 #define KSI_DataHashList_sort(lst, cmp) KSI_APPLY_TO_NOT_NULL((lst), sort, ((lst), (cmp)))
413 #define KSI_DataHashList_foldl(lst, foldCtx, foldFn) (((lst) != NULL) ? (((lst)->foldl != NULL) ? ((lst)->foldl((lst), (foldCtx), (foldFn))) : KSI_INVALID_STATE) : KSI_OK)
414 #define KSI_DataHashList_find(lst, o,f, i) KSI_APPLY_TO_NOT_NULL((lst), find, ((lst), (o), (f), (i)))
415 
419 #ifdef __cplusplus
420 }
421 #endif
422 
423 #endif /* KSI_HASH_H_ */
#define KSI_DEFINE_EXTERN(e)
Definition: common.h:87
#define KSI_FN_DEPRECATED(decl, comment)
Definition: common.h:50
#define KSI_VAR_DEPRECATED(decl, comment)
Definition: common.h:64
struct KSI_OctetString_st KSI_OctetString
Definition: types_base.h:99
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:78
KSI_DataHash * KSI_DataHash_ref(KSI_DataHash *o)
int KSI_DataHash_clone(KSI_DataHash *from, KSI_DataHash **to)
time_t KSI_HashAlgorithm_getObsoleteFrom(KSI_HashAlgorithm algo_id)
const char * KSI_getHashAlgorithmName(KSI_HashAlgorithm algo_id)
int KSI_DataHash_fromDigest(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, const unsigned char *digest, size_t digest_length, KSI_DataHash **hash)
time_t KSI_HashAlgorithm_getDeprecatedFrom(KSI_HashAlgorithm algo_id)
int KSI_DataHasher_addOctetString(KSI_DataHasher *hasher, const KSI_OctetString *data)
const int KSI_HASHALG_INVALID
int KSI_DataHash_getHashAlg(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id)
int KSI_DataHash_getImprint(const KSI_DataHash *hash, const unsigned char **imprint, size_t *imprint_length)
int KSI_DataHasher_reset(KSI_DataHasher *hasher)
void KSI_DataHasher_free(KSI_DataHasher *hasher)
struct KSI_DataHash_st KSI_DataHash
Definition: hash.h:52
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_isHashAlgorithmSupported(KSI_HashAlgorithm algo_id)
enum KSI_HashAlgorithm_en KSI_HashAlgorithm
int KSI_checkHashAlgorithmAt(KSI_HashAlgorithm algo_id, time_t used_at)
int KSI_DataHash_fromImprint(KSI_CTX *ctx, const unsigned char *imprint, size_t imprint_length, KSI_DataHash **hash)
KSI_HashAlgorithm KSI_getHashAlgorithmByName(const char *name)
int KSI_DataHasher_close(KSI_DataHasher *hasher, KSI_DataHash **hash)
int KSI_DataHash_createZero(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHash **hsh)
KSI_HashAlgorithm_en
Definition: hash.h:60
int KSI_DataHasher_open(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHasher **hasher)
char * KSI_DataHash_toString(const KSI_DataHash *hsh, char *buf, size_t buf_len)
int KSI_isHashAlgorithmTrusted(KSI_HashAlgorithm algo_id)
int KSI_DataHash_equals(const KSI_DataHash *left, const KSI_DataHash *right)
const int KSI_HASHALG_SHA3_244
int KSI_DataHash_create(KSI_CTX *ctx, const void *data, size_t data_length, KSI_HashAlgorithm algo_id, KSI_DataHash **hash)
unsigned int KSI_HashAlgorithm_getBlockSize(KSI_HashAlgorithm algo_id)
struct KSI_DataHasher_st KSI_DataHasher
Definition: hash.h:46
void KSI_DataHash_free(KSI_DataHash *hash)
int KSI_DataHasher_addImprint(KSI_DataHasher *hasher, const KSI_DataHash *hsh)
unsigned int KSI_getHashLength(KSI_HashAlgorithm algo_id)
@ KSI_HASHALG_SHA2_512
Definition: hash.h:71
@ __KSI_HASHALG_DO_NOT_USE
Definition: hash.h:61
@ KSI_HASHALG_SHA1
Definition: hash.h:63
@ KSI_HASHALG_SHA3_384
Definition: hash.h:77
@ KSI_HASHALG_SHA3_512
Definition: hash.h:79
@ KSI_HASHALG_SM3
Definition: hash.h:81
@ KSI_HASHALG_SHA2_256
Definition: hash.h:65
@ KSI_HASHALG_SHA3_256
Definition: hash.h:75
@ KSI_NUMBER_OF_KNOWN_HASHALGS
Definition: hash.h:84
@ KSI_HASHALG_SHA3_224
Definition: hash.h:73
@ KSI_HASHALG_SHA2_384
Definition: hash.h:69
@ KSI_HASHALG_INVALID_VALUE
Definition: hash.h:87
@ KSI_HASHALG_RIPEMD160
Definition: hash.h:67
#define KSI_DEFINE_LIST(type)
Definition: list.h:96
#define KSI_DEFINE_REF(typ)
Definition: types_base.h:39
#define KSI_DEFINE_FN_FROM_TLV(typ)
Definition: types_base.h:30
#define KSI_DEFINE_FN_TO_TLV(typ)
Definition: types_base.h:34