Lines Matching refs:hash_cache
12 static int hash_cache_calc(struct crypto_hash_cache *hash_cache, const u8 *data, in hash_cache_calc() argument
15 crypto_hash_calc direct_calc = hash_cache->direct_calc; in hash_cache_calc()
18 if (!hash_cache->cache) { in hash_cache_calc()
19 hash_cache->cache = (u8 *)memalign(CONFIG_SYS_CACHELINE_SIZE, in hash_cache_calc()
21 if (!hash_cache->cache) in hash_cache_calc()
24 hash_cache->cache_size = 0; in hash_cache_calc()
30 if (hash_cache->cache_size + data_len <= HASH_CACHE_SIZE) { in hash_cache_calc()
34 memcpy(hash_cache->cache + hash_cache->cache_size, data, in hash_cache_calc()
36 hash_cache->cache_size += data_len; in hash_cache_calc()
42 hash_cache->cache_size); in hash_cache_calc()
44 ret = direct_calc(hash_cache->user_data, in hash_cache_calc()
45 hash_cache->cache, in hash_cache_calc()
46 hash_cache->cache_size, in hash_cache_calc()
47 &hash_cache->is_started, in hash_cache_calc()
57 tmp_len = HASH_CACHE_SIZE - hash_cache->cache_size; in hash_cache_calc()
60 memcpy(hash_cache->cache + hash_cache->cache_size, in hash_cache_calc()
63 ret = direct_calc(hash_cache->user_data, hash_cache->cache, in hash_cache_calc()
64 HASH_CACHE_SIZE, &hash_cache->is_started, 0); in hash_cache_calc()
70 hash_cache->cache_size = 0; in hash_cache_calc()
96 struct crypto_hash_cache *hash_cache = NULL; in crypto_hash_cache_alloc() local
101 hash_cache = malloc(sizeof(struct crypto_hash_cache)); in crypto_hash_cache_alloc()
102 if (!hash_cache) in crypto_hash_cache_alloc()
105 memset(hash_cache, 0x00, sizeof(*hash_cache)); in crypto_hash_cache_alloc()
107 hash_cache->direct_calc = direct_calc; in crypto_hash_cache_alloc()
108 hash_cache->user_data = user_data; in crypto_hash_cache_alloc()
109 hash_cache->data_align = data_align; in crypto_hash_cache_alloc()
110 hash_cache->len_align = len_align; in crypto_hash_cache_alloc()
111 hash_cache->left_len = total; in crypto_hash_cache_alloc()
113 return hash_cache; in crypto_hash_cache_alloc()
116 void crypto_hash_cache_free(struct crypto_hash_cache *hash_cache) in crypto_hash_cache_free() argument
118 if (!hash_cache) in crypto_hash_cache_free()
121 if (hash_cache->cache) in crypto_hash_cache_free()
122 free(hash_cache->cache); in crypto_hash_cache_free()
124 free(hash_cache); in crypto_hash_cache_free()
127 int crypto_hash_update_with_cache(struct crypto_hash_cache *hash_cache, in crypto_hash_update_with_cache() argument
130 crypto_hash_calc direct_calc = hash_cache->direct_calc; in crypto_hash_update_with_cache()
136 if (hash_cache->left_len < data_len) in crypto_hash_update_with_cache()
139 is_last = hash_cache->left_len == data_len ? 1 : 0; in crypto_hash_update_with_cache()
141 if (!hash_cache->use_cache && in crypto_hash_update_with_cache()
142 IS_ALIGNED((ulong)data, hash_cache->data_align)) { in crypto_hash_update_with_cache()
144 if (IS_ALIGNED(data_len, hash_cache->len_align) || is_last) { in crypto_hash_update_with_cache()
154 hash_cache->len_align); in crypto_hash_update_with_cache()
156 cache_data_len = data_len % hash_cache->len_align; in crypto_hash_update_with_cache()
157 hash_cache->use_cache = 1; in crypto_hash_update_with_cache()
164 hash_cache->use_cache = 1; in crypto_hash_update_with_cache()
170 ret = direct_calc(hash_cache->user_data, in crypto_hash_update_with_cache()
172 &hash_cache->is_started, is_last); in crypto_hash_update_with_cache()
175 hash_cache->left_len -= direct_data_len; in crypto_hash_update_with_cache()
181 ret = hash_cache_calc(hash_cache, cache_data, in crypto_hash_update_with_cache()
185 hash_cache->left_len -= cache_data_len; in crypto_hash_update_with_cache()
190 if (hash_cache->cache) { in crypto_hash_update_with_cache()
191 free(hash_cache->cache); in crypto_hash_update_with_cache()
192 hash_cache->cache = NULL; in crypto_hash_update_with_cache()