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 
91  #define KSI_MAX_IMPRINT_LEN 65 /* Algorithm ID (1 byte) + longest digest. */
92 
104  int KSI_DataHasher_open(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHasher **hasher);
105 
114 
125  int KSI_DataHasher_add(KSI_DataHasher *hasher, const void *data, size_t data_length);
126 
133  int KSI_DataHasher_addImprint(KSI_DataHasher *hasher, const KSI_DataHash *hsh);
134 
142 
151  int KSI_DataHasher_close(KSI_DataHasher *hasher, KSI_DataHash **hash);
152 
159  void KSI_DataHasher_free(KSI_DataHasher *hasher);
160 
168  void KSI_DataHash_free(KSI_DataHash *hash);
169 
182  int KSI_DataHash_create(KSI_CTX *ctx, const void *data, size_t data_length, KSI_HashAlgorithm algo_id, KSI_DataHash **hash);
183 
193 
210  int KSI_DataHash_extract(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id, const unsigned char **digest, size_t *digest_length);
211 
224  int KSI_DataHash_fromDigest(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, const unsigned char *digest, size_t digest_length, KSI_DataHash **hash);
225 
235  int KSI_DataHash_getImprint(const KSI_DataHash *hash, const unsigned char **imprint, size_t *imprint_length);
236 
248  int KSI_DataHash_fromImprint(KSI_CTX *ctx, const unsigned char *imprint, size_t imprint_length, KSI_DataHash **hash);
249 
266  KSI_HashAlgorithm KSI_getHashAlgorithmByName(const char *name);
267 
276  unsigned int KSI_getHashLength(KSI_HashAlgorithm algo_id);
277 
284  unsigned int KSI_HashAlgorithm_getBlockSize(KSI_HashAlgorithm algo_id);
285 
292  time_t KSI_HashAlgorithm_getDeprecatedFrom(KSI_HashAlgorithm algo_id);
293 
300  time_t KSI_HashAlgorithm_getObsoleteFrom(KSI_HashAlgorithm algo_id);
301 
316  int KSI_isHashAlgorithmTrusted(KSI_HashAlgorithm algo_id);
317 
328  int KSI_checkHashAlgorithmAt(KSI_HashAlgorithm algo_id, time_t used_at);
329 
338  int KSI_isHashAlgorithmSupported(KSI_HashAlgorithm algo_id);
339 
348  const char *KSI_getHashAlgorithmName(KSI_HashAlgorithm algo_id);
349 
359  int KSI_DataHash_equals(const KSI_DataHash *left, const KSI_DataHash *right);
360 
363 
370  int KSI_DataHash_getHashAlg(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id);
371 
379  char *KSI_DataHash_toString(const KSI_DataHash *hsh, char *buf, size_t buf_len);
380 
388  int KSI_DataHash_createZero(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHash **hsh);
389 
392 #define KSI_DataHashList_append(lst, o) KSI_APPLY_TO_NOT_NULL((lst), append, ((lst), (o)))
393 #define KSI_DataHashList_remove(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), removeElement, ((lst), (pos), (o)))
394 #define KSI_DataHashList_indexOf(lst, o, i) KSI_APPLY_TO_NOT_NULL((lst), indexOf, ((lst), (o), (i)))
395 #define KSI_DataHashList_insertAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), insertAt, ((lst), (pos), (o)))
396 #define KSI_DataHashList_replaceAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), replaceAt, ((lst), (pos), (o)))
397 #define KSI_DataHashList_elementAt(lst, pos, o) KSI_APPLY_TO_NOT_NULL((lst), elementAt, ((lst), (pos), (o)))
398 #define KSI_DataHashList_length(lst) (((lst) != NULL && (lst)->length != NULL) ? (lst)->length((lst)) : 0)
399 #define KSI_DataHashList_sort(lst, cmp) KSI_APPLY_TO_NOT_NULL((lst), sort, ((lst), (cmp)))
400 #define KSI_DataHashList_foldl(lst, foldCtx, foldFn) (((lst) != NULL) ? (((lst)->foldl != NULL) ? ((lst)->foldl((lst), (foldCtx), (foldFn))) : KSI_INVALID_STATE) : KSI_OK)
401 
405 #ifdef __cplusplus
406 }
407 #endif
408 
409 #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: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:73
Definition: hash.h:60
void KSI_DataHash_free(KSI_DataHash *hash)
KSI_HashAlgorithm_en
Definition: hash.h:58
#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)
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)