blob: d28db405d9210a7e262dbb6c6d1188ea3636adfd [file] [log] [blame]
/*
* Cryptographic API.
*
* HMAC: Keyed-Hashing for Message Authentication (RFC2104).
* SHA-256 is used as an underlying hash function.
*
* Author : Igor Shcheglakov (i.shcheglako@samsung.com)
* Date : 15 Dec 2017
*
* Copyright (C) 2017 Samsung Electronics Co., Ltd.
*
*/
#ifndef _FMP_HMAC_SHA256_H
#define _FMP_HMAC_SHA256_H
#include "sha256.h"
struct hmac_sha256_ctx {
struct shash_desc inner_ctx;
struct shash_desc outer_ctx;
};
typedef struct hmac_sha256_ctx HMAC_SHA256_CTX;
/* Initialize hashing context using a key of key_len bytes.
*
* Return zero on success and negative otherwise
*/
int hmac_sha256_init(struct hmac_sha256_ctx *ctx, const u8 *key,
unsigned int key_len);
/* Hash data_len bytes of data
*
* Return zero on success and negative otherwise
*/
int hmac_sha256_update(struct hmac_sha256_ctx *ctx, const u8 *data,
unsigned int data_len);
/* Add final padding to a hash and write resulting HMAC to out.
* There must be at least SHA256_DIGEST_LENGTH bytes of space in out
*
* Return zero on success and negative otherwise
*/
int hmac_sha256_final(struct hmac_sha256_ctx *ctx, u8 *out);
/* Hash data_len bytes of data using key of key_len bytes.
* Write resulting HMAC to out. There must be at least SHA256_DIGEST_LENGTH
* bytes of space in out
*
* Return zero on success and negative otherwise
*/
int hmac_sha256(const u8 *key, unsigned int key_len, const u8 *data,
unsigned int data_len, u8 *out);
/* Cleanup allocated resources */
void hmac_sha256_ctx_cleanup(struct hmac_sha256_ctx *ctx);
#endif /* _FMP_HMAC_SHA256_H */