Guardtime KSI c SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
110  int KSI_DataHasher_open(KSI_CTX *ctx, KSI_HashAlgorithm algo_id, KSI_DataHasher **hasher);
111 
120 
131  int KSI_DataHasher_add(KSI_DataHasher *hasher, const void *data, size_t data_length);
132 
139  int KSI_DataHasher_addImprint(KSI_DataHasher *hasher, const KSI_DataHash *hsh);
140 
148 
157  int KSI_DataHasher_close(KSI_DataHasher *hasher, KSI_DataHash **hash);
158 
165  void KSI_DataHasher_free(KSI_DataHasher *hasher);
166 
174  void KSI_DataHash_free(KSI_DataHash *hash);
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 
361  const char *KSI_getHashAlgorithmName(KSI_HashAlgorithm algo_id);
362 
372  int KSI_DataHash_equals(const KSI_DataHash *left, const KSI_DataHash *right);
373 
376 
383  int KSI_DataHash_getHashAlg(const KSI_DataHash *hash, KSI_HashAlgorithm *algo_id);
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_ */
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)
Definition: hash.h:61
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
const int KSI_HASHALG_INVALID
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
#define KSI_DEFINE_EXTERN(e)
Definition: common.h:87
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)
Definition: hash.h:87
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
void KSI_DataHash_free(KSI_DataHash *hash)
KSI_HashAlgorithm_en
Definition: hash.h:60
#define KSI_VAR_DEPRECATED(decl, comment)
Definition: common.h:64
#define KSI_DEFINE_LIST(type)
Definition: list.h:159
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)