1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #4715 from OlegHahm/crypto_to_hashes

hashes: cleanup
This commit is contained in:
Oleg Hahm 2016-02-04 15:46:41 +01:00
commit 6ace8234cf
20 changed files with 87 additions and 53 deletions

View File

@ -7,7 +7,7 @@
*/
/**
* @ingroup sys_checksum_crc16_ccitt
* @ingroup sys_crc_crc16_ccitt
* @{
*
* @file
@ -21,7 +21,7 @@
#include <stdint.h>
#include <stdlib.h>
#include "checksum/crc16_ccitt.h"
#include "crc/crc16_ccitt.h"
static const uint16_t _crc16_lookuptable[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,

View File

@ -7,7 +7,7 @@
*/
/**
* @defgroup sys_checksum Checksum
* @defgroup sys_crc CRC Cyclic redundancy checks
* @ingroup sys
* @brief Checksum function libraries
* @brief CRC hashing functions
*/

View File

@ -44,7 +44,4 @@
*
* Additional examples can be found in the test suite.
*
* @section hashes Hashes
*
* RIOT currently supports sha256 as a cryptographic hash implementation.
*/

38
sys/hashes/doc.txt Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2016 INRIA
*
* 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.
*/
/**
* @defgroup sys_hashes Hashes
* @ingroup sys
*
* @brief RIOT provides a collection of hash algorithms.
*
* RIOT supports the following hash functions:
*
* @section Checksums
*
* * Fletcher-16
* * Fletcher-32
*
* @section Non-cryptographic hash functions
*
* * Bernstein hash djb2i (http://www.cse.yorku.ca/~oz/hash.html)
* * sdbm (http://www.cse.yorku.ca/~oz/hash.html)
* * Kernighan and Ritchie
* * Shift, And, Xor
* * Donald E. Knuth
* * FowlerNollVo hash function
* * Rotating Hash
* * One at a time Hash
*
* @section Unkeyed cryptographic hash functions
*
* * MD5
* * SHA-256
*
*/

View File

@ -28,7 +28,7 @@
*/
/**
* @ingroup sys_crypto
* @ingroup sys_hashes
* @{
*
* @file
@ -43,7 +43,7 @@
#include <string.h>
#include "crypto/sha256.h"
#include "hashes/sha256.h"
#include "board.h"
#ifdef __BIG_ENDIAN__

View File

@ -7,8 +7,8 @@
*/
/**
* @defgroup sys_checksum_crc16_ccitt CRC16-CCITT
* @ingroup sys_checksum
* @defgroup sys_crc_crc16_ccitt CRC16-CCITT
* @ingroup sys_crc
*
* @brief CRC16-CCITT checksum algorithm
* @details This implementation of CRC16 is based on the CCITT

View File

@ -7,7 +7,7 @@
*/
/**
* @defgroup sys_hashes Hashes
* @ingroup sys_hashes Hashes
* @ingroup sys
* @brief Hash function library
* @{
@ -31,7 +31,7 @@ extern "C" {
#endif
/**
* @brief djb2_hash
* @brief djb2
*
* HISTORY
* This algorithm (k=33) was first reported by Dan Bernstein many years
@ -50,7 +50,7 @@ extern "C" {
uint32_t djb2_hash(const uint8_t *buf, size_t len);
/**
* @brief sdbm_hash
* @brief sdbm
*
* HISTORY
* This algorithm was created for sdbm (a public-domain reimplementation
@ -75,7 +75,7 @@ uint32_t djb2_hash(const uint8_t *buf, size_t len);
uint32_t sdbm_hash(const uint8_t *buf, size_t len);
/**
* @brief lose lose
* @brief Kernighan and Ritchie
*
* HISTORY
* This hash function appeared in K&R (1st ed) but at least the reader
@ -100,9 +100,7 @@ uint32_t sdbm_hash(const uint8_t *buf, size_t len);
uint32_t kr_hash(const uint8_t *buf, size_t len);
/**
* @brief sax_hash
*
* Shift, Add, XOR
* @brief Shift, Add, XOR
*
* @param buf input buffer to hash
* @param len length of buffer
@ -111,7 +109,7 @@ uint32_t kr_hash(const uint8_t *buf, size_t len);
uint32_t sax_hash(const uint8_t *buf, size_t len);
/**
* @brief dek_hash
* @brief Donald E. Knuth
*
* HISTORY
* Proposed by Donald E. Knuth in The Art Of Computer Programming Vol. 3,
@ -124,7 +122,7 @@ uint32_t sax_hash(const uint8_t *buf, size_t len);
uint32_t dek_hash(const uint8_t *buf, size_t len);
/**
* @brief fnv_hash
* @brief FowlerNollVo
*
* NOTE
* For a more fully featured and modern version of this hash, see fnv32.c
@ -137,7 +135,7 @@ uint32_t fnv_hash(const uint8_t *buf, size_t len);
/**
* @brief rotating_hash
* @brief Rotating
*
* found on
* http://burtleburtle.net/bob/hash/doobs.html
@ -149,7 +147,7 @@ uint32_t fnv_hash(const uint8_t *buf, size_t len);
uint32_t rotating_hash(const uint8_t *buf, size_t len);
/**
* @brief one_at_a_time_hash
* @brief One at a time
*
* found on
* http://burtleburtle.net/bob/hash/doobs.html

View File

@ -29,7 +29,7 @@
/**
* @ingroup sys_crypto
* @ingroup sys_hashes
* @{
*
* @file

View File

@ -1 +0,0 @@
USEMODULE += checksum

View File

@ -0,0 +1 @@
USEMODULE += crc

View File

@ -10,9 +10,9 @@
#include "embUnit/embUnit.h"
#include "checksum/crc16_ccitt.h"
#include "crc/crc16_ccitt.h"
#include "tests-checksum.h"
#include "tests-crc.h"
static int calc_and_compare_crc_with_update(const unsigned char *buf,
size_t len, size_t split, uint16_t expected)
@ -32,7 +32,7 @@ static int calc_and_compare_crc(const unsigned char *buf, size_t len,
return result == expected;
}
static void test_checksum_crc16_ccitt_sequence(void)
static void test_crc_crc16_ccitt_sequence(void)
{
/* Reference values according to
* http://srecord.sourceforge.net/crc16-ccitt.html */
@ -85,13 +85,13 @@ static void test_checksum_crc16_ccitt_sequence(void)
}
}
Test *tests_checksum_crc16_ccitt_tests(void)
Test *tests_crc_crc16_ccitt_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_checksum_crc16_ccitt_sequence),
new_TestFixture(test_crc_crc16_ccitt_sequence),
};
EMB_UNIT_TESTCALLER(checksum_crc16_ccitt_tests, NULL, NULL, fixtures);
EMB_UNIT_TESTCALLER(crc_crc16_ccitt_tests, NULL, NULL, fixtures);
return (Test *)&checksum_crc16_ccitt_tests;
return (Test *)&crc_crc16_ccitt_tests;
}

View File

@ -6,9 +6,9 @@
* directory for more details.
*/
#include "tests-checksum.h"
#include "tests-crc.h"
void tests_checksum(void)
void tests_crc(void)
{
TESTS_RUN(tests_checksum_crc16_ccitt_tests());
TESTS_RUN(tests_crc_crc16_ccitt_tests());
}

View File

@ -11,7 +11,7 @@
* @{
*
* @file
* @brief Unittests for the ``checksum`` module
* @brief Unittests for the ``crc`` module
*
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
*/
@ -28,14 +28,14 @@ extern "C" {
/**
* @brief The entry point of this test suite.
*/
void tests_checksum(void);
void tests_crc(void);
/**
* @brief Generates tests for checksum/crc16_ccitt.h
* @brief Generates tests for crc/crc16_ccitt.h
*
* @return embUnit tests if successful, NULL if not.
*/
Test *tests_checksum_crc16_ccitt_tests(void);
Test *tests_crc_crc16_ccitt_tests(void);
#ifdef __cplusplus
}

View File

@ -11,7 +11,6 @@
void tests_crypto(void)
{
TESTS_RUN(tests_crypto_sha256_tests());
TESTS_RUN(tests_crypto_chacha_tests());
TESTS_RUN(tests_crypto_aes_tests());
TESTS_RUN(tests_crypto_3des_tests());

View File

@ -31,13 +31,6 @@ extern "C" {
*/
void tests_crypto(void);
/**
* @brief Generates tests for crypto/sha256.h
*
* @return embUnit tests if successful, NULL if not.
*/
Test *tests_crypto_sha256_tests(void);
/**
* @brief Generates tests for crypto/chacha.h
*

View File

@ -14,9 +14,9 @@
#include "embUnit/embUnit.h"
#include "crypto/sha256.h"
#include "hashes/sha256.h"
#include "tests-crypto.h"
#include "tests-hashes.h"
static int compare_str_vs_digest(const char *str,
const unsigned char hash[SHA256_DIGEST_LENGTH])
@ -47,7 +47,7 @@ static int calc_and_compare_hash(const char *str, const char *expected)
return compare_str_vs_digest(expected, hash);
}
static void test_crypto_sha256_hash_sequence(void)
static void test_hashes_sha256_hash_sequence(void)
{
TEST_ASSERT(calc_and_compare_hash("1234567890_1",
"3eda9ffe5537a588f54d0b2a453e5fa932986d0bc0f9556924f5c2379b2c91b0"));
@ -81,14 +81,14 @@ static void test_crypto_sha256_hash_sequence(void)
"c19d3bf8588897076873f1a0a106ba840ca46bd1179d592953acecc4df59593c"));
}
Test *tests_crypto_sha256_tests(void)
Test *tests_hashes_sha256_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_crypto_sha256_hash_sequence),
new_TestFixture(test_hashes_sha256_hash_sequence),
};
EMB_UNIT_TESTCALLER(crypto_sha256_tests, NULL, NULL,
EMB_UNIT_TESTCALLER(hashes_sha256_tests, NULL, NULL,
fixtures);
return (Test *)&crypto_sha256_tests;
return (Test *)&hashes_sha256_tests;
}

View File

@ -23,4 +23,5 @@
void tests_hashes(void)
{
TESTS_RUN(tests_hashes_md5_tests());
TESTS_RUN(tests_hashes_sha256_tests());
}

View File

@ -37,6 +37,14 @@ void tests_hashes(void);
*/
Test *tests_hashes_md5_tests(void);
/**
* @brief Generates tests for hashes/sha256.h
*
* @return embUnit tests if successful, NULL if not.
*/
Test *tests_hashes_sha256_tests(void);
#ifdef __cplusplus
}
#endif