2015-04-02 08:56:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup sys_crypto
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file helper.h
|
|
|
|
* @brief helper functions for sys_crypto_modes
|
|
|
|
*
|
|
|
|
* @author Freie Universitaet Berlin, Computer Systems & Telematics
|
|
|
|
* @author Nico von Geyso <nico.geyso@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#ifndef CRYPTO_HELPER_H
|
|
|
|
#define CRYPTO_HELPER_H
|
2015-04-02 08:56:18 +02:00
|
|
|
|
2016-02-27 01:12:02 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2015-04-02 08:56:18 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Increment a counter encoded in an 16 octet block. The counter is
|
|
|
|
* encoded from the least significant bit in the following form:
|
|
|
|
* block[15-L..15])
|
|
|
|
*
|
|
|
|
* @param block encoded block
|
|
|
|
* @param L length of counter
|
|
|
|
*/
|
|
|
|
void crypto_block_inc_ctr(uint8_t block[16], int L);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Compares two blocks of same size in deterministic time.
|
|
|
|
*
|
|
|
|
* @param a block a
|
|
|
|
* @param b block b
|
|
|
|
* @param len size of both blocks
|
|
|
|
*
|
|
|
|
* @returns 0 iff the blocks are non-equal.
|
|
|
|
*/
|
2018-10-21 20:27:33 +02:00
|
|
|
int crypto_equals(const uint8_t *a, const uint8_t *b, size_t len);
|
2015-04-02 08:56:18 +02:00
|
|
|
|
2018-10-21 20:31:54 +02:00
|
|
|
/**
|
|
|
|
* @brief Secure wipe function.
|
|
|
|
*
|
|
|
|
* This wipe function zeros the supplied buffer in a way that the compiler is
|
|
|
|
* not allowed to optimize. This can be used to erase secrets from memory.
|
|
|
|
*
|
|
|
|
* Note that this function on its own could be insufficient against (data
|
|
|
|
* remanence) attacks. It is outside the scope of this function to thoroughly
|
|
|
|
* shred the memory area.
|
|
|
|
*
|
|
|
|
* @param[in] buf buffer to wipe
|
|
|
|
* @param[in] len size of the buffer in bytes
|
|
|
|
*/
|
|
|
|
void crypto_secure_wipe(void *buf, size_t len);
|
|
|
|
|
2015-04-02 08:56:18 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* CRYPTO_HELPER_H */
|
2022-08-11 16:24:37 +02:00
|
|
|
/** @} */
|