/* test_hmac_prng.c - TinyCrypt implementation of some HMAC-PRNG tests */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
DESCRIPTION
This module tests the following PRNG routines:
Scenarios tested include:
- HMAC-PRNG init
- HMAC-PRNG reseed
- HMAC-PRNG generate)
*/
#include <tinycrypt/hmac_prng.h>
#include <tinycrypt/constants.h>
#include <test_utils.h>
#include <stdio.h>
struct hmac_prng_test_vector {
uint8_t entropyinputlen;
uint8_t noncelen;
uint8_t personalizationstringlen;
uint8_t additionalinputlen;
uint8_t returnedbitslen;
uint8_t entropyinput[32];
uint8_t nonce[16];
uint8_t personalizationstring[32];
uint8_t entropyinputreseed[32];
uint8_t additionalinputreseed[32];
uint8_t returnedbits[128];
};
unsigned int do_hmac_prng_pr_false_test(unsigned int testnum, const struct
hmac_prng_test_vector *vec)
{
struct tc_hmac_prng_struct h;
uint8_t random[128];
uint32_t seed_material_size;
uint8_t seed_material[32 + 16 + 32]; /*entropyinput || nonce || personalizationstring */
unsigned int result = TC_PASS;
uint8_t *p = seed_material;
memset(&h, 0x0, sizeof(h));
if (vec->entropyinputlen > 0) {
memcpy(p, vec->entropyinput, vec->entropyinputlen);
p += vec->entropyinputlen;
}
if (vec->noncelen > 0) {
memcpy(p, vec->nonce, vec->noncelen);
p += vec->noncelen;
}
if (vec->personalizationstringlen > 0) {
memcpy(p, vec->personalizationstring, vec->personalizationstringlen);
}
seed_material_size = vec->entropyinputlen + vec->noncelen + vec->personalizationstringlen;
(void)tc_hmac_prng_init(&h, seed_material, seed_material_size);
(void)tc_hmac_prng_reseed(&h, vec->entropyinputreseed, vec->entropyinputlen, 0, 0);
(void)tc_hmac_prng_generate(random, vec->returnedbitslen, &h);
(void)tc_hmac_prng_generate(random, vec->returnedbitslen, &h);
result = check_result(testnum, vec->returnedbits, vec->returnedbitslen, random, vec->returnedbitslen);
return result;
}
unsigned int test_1(void)
{
unsigned int result = TC_PASS;
const struct hmac_prng_test_vector vec = {
32,
16,
0,
0,
128,
{
0x06, 0x03, 0x2c, 0xd5, 0xee, 0xd3, 0x3f, 0x39, 0x26, 0x5f, 0x49, 0xec,
0xb1, 0x42, 0xc5, 0x11, 0xda, 0x9a, 0xff, 0x2a, 0xf7, 0x12, 0x03, 0xbf,
0xfa, 0xf3, 0x4a, 0x9c, 0xa5, 0xbd, 0x9c, 0x0d,
},
{
0x0e, 0x66, 0xf7, 0x1e, 0xdc, 0x43, 0xe4, 0x2a, 0x45, 0xad, 0x3c, 0x6f,
0xc6, 0xcd, 0xc4, 0xdf,
},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
0x01, 0x92, 0x0a, 0x4e, 0x66, 0x9e, 0xd3, 0xa8, 0x5a, 0xe8, 0xa3, 0x3b,
0x35, 0xa7, 0x4a, 0xd7, 0xfb, 0x2a, 0x6b, 0xb4, 0xcf, 0x39, 0x5c, 0xe0,
0x03, 0x34, 0xa9, 0xc9, 0xa5, 0xa5, 0xd5, 0x52,
},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
0x76, 0xfc, 0x79, 0xfe, 0x9b, 0x50, 0xbe, 0xcc, 0xc9, 0x91, 0xa1, 0x1b,
0x56, 0x35, 0x78, 0x3a, 0x83, 0x53, 0x6a, 0xdd, 0x03, 0xc1, 0x57, 0xfb,
0x30, 0x64, 0x5e, 0x61, 0x1c, 0x28, 0x98, 0xbb, 0x2b, 0x1b, 0xc2, 0x15,
0x00, 0x02, 0x09, 0x20, 0x8c, 0xd5, 0x06, 0xcb, 0x28, 0xda, 0x2a, 0x51,
0xbd, 0xb0, 0x38, 0x26, 0xaa, 0xf2, 0xbd, 0x23, 0x35, 0xd5, 0x76, 0xd5,
0x19, 0x16, 0x08, 0x42, 0xe7, 0x15, 0x8a, 0xd0, 0x94, 0x9d, 0x1a, 0x9e,
0xc3, 0xe6, 0x6e, 0xa1, 0xb1, 0xa0, 0x64, 0xb0, 0x05, 0xde, 0x91, 0x4e,
0xac, 0x2e, 0x9d, 0x4f, 0x2d, 0x72, 0xa8, 0x61, 0x6a, 0x80, 0x22, 0x54,
0x22, 0x91, 0x82, 0x50, 0xff, 0x66, 0xa4, 0x1b, 0xd2, 0xf8, 0x64, 0xa6,
0xa3, 0x8c, 0xc5, 0xb6, 0x49, 0x9d, 0xc4, 0x3f, 0x7f, 0x2b, 0xd0, 0x9e,
0x1e, 0x0f, 0x8f, 0x58, 0x85, 0x93, 0x51, 0x24,
}
};
TC_PRINT("HMAC-PRNG %s:\n", __func__);
result = do_hmac_prng_pr_false_test(1, &vec);
TC_END_RESULT(result);
return result;
}
unsigned int test_2(void)
{
unsigned int result = TC_PASS;
const struct hmac_prng_test_vector vec = {
32,
16,
0,
0,
128,
{
0xaa, 0xdc, 0xf3, 0x37, 0x78, 0x8b, 0xb8, 0xac, 0x01, 0x97, 0x66, 0x40,
0x72, 0x6b, 0xc5, 0x16, 0x35, 0xd4, 0x17, 0x77, 0x7f, 0xe6, 0x93, 0x9e,
0xde, 0xd9, 0xcc, 0xc8, 0xa3, 0x78, 0xc7, 0x6a,
},
{
0x9c, 0xcc, 0x9d, 0x80, 0xc8, 0x9a, 0xc5, 0x5a, 0x8c, 0xfe, 0x0f, 0x99,
0x94, 0x2f, 0x5a, 0x4d,
},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
0x03, 0xa5, 0x77, 0x92, 0x54, 0x7e, 0x0c, 0x98, 0xea, 0x17, 0x76, 0xe4,
0xba, 0x80, 0xc0, 0x07, 0x34, 0x62, 0x96, 0xa5, 0x6a, 0x27, 0x0a, 0x35,
0xfd, 0x9e, 0xa2, 0x84, 0x5c, 0x7e, 0x81, 0xe2,
},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
0x17, 0xd0, 0x9f, 0x40, 0xa4, 0x37, 0x71, 0xf4, 0xa2, 0xf0, 0xdb, 0x32,
0x7d, 0xf6, 0x37, 0xde, 0xa9, 0x72, 0xbf, 0xff, 0x30, 0xc9, 0x8e, 0xbc,
0x88, 0x42, 0xdc, 0x7a, 0x9e, 0x3d, 0x68, 0x1c, 0x61, 0x90, 0x2f, 0x71,
0xbf, 0xfa, 0xf5, 0x09, 0x36, 0x07, 0xfb, 0xfb, 0xa9, 0x67, 0x4a, 0x70,
0xd0, 0x48, 0xe5, 0x62, 0xee, 0x88, 0xf0, 0x27, 0xf6, 0x30, 0xa7, 0x85,
0x22, 0xec, 0x6f, 0x70, 0x6b, 0xb4, 0x4a, 0xe1, 0x30, 0xe0, 0x5c, 0x8d,
0x7e, 0xac, 0x66, 0x8b, 0xf6, 0x98, 0x0d, 0x99, 0xb4, 0xc0, 0x24, 0x29,
0x46, 0x45, 0x23, 0x99, 0xcb, 0x03, 0x2c, 0xc6, 0xf9, 0xfd, 0x96, 0x28,
0x47, 0x09, 0xbd, 0x2f, 0xa5, 0x65, 0xb9, 0xeb, 0x9f, 0x20, 0x04, 0xbe,
0x6c, 0x9e, 0xa9, 0xff, 0x91, 0x28, 0xc3, 0xf9, 0x3b, 0x60, 0xdc, 0x30,
0xc5, 0xfc, 0x85, 0x87, 0xa1, 0x0d, 0xe6, 0x8c,
}
};
TC_PRINT("HMAC-PRNG %s:\n", __func__);
result = do_hmac_prng_pr_false_test(2, &vec);
TC_END_RESULT(result);
return result;
}
unsigned int test_3(void)
{
unsigned int result = TC_PASS;
const struct hmac_prng_test_vector vec = {
32,
16,
0,
0,
128,
{
0x62, 0xcd, 0xa4, 0x41, 0xdd, 0x80, 0x2c, 0x76, 0x52, 0xc0, 0x0b, 0x99,
0xca, 0xc3, 0x65, 0x2a, 0x64, 0xfc, 0x75, 0x38, 0x8d, 0xc9, 0xad, 0xcf,
0x76, 0x35, 0x30, 0xac, 0x31, 0xdf, 0x92, 0x14,
},
{
0x5f, 0xdc, 0x89, 0x7a, 0x0c, 0x1c, 0x48, 0x22, 0x04, 0xef, 0x07, 0xe0,
0x80, 0x5c, 0x
没有合适的资源?快使用搜索试试~ 我知道了~
tinycrypt是一个密码算法库,专注于小型、简单的实现。.zip
共55个文件
c:27个
h:17个
makefile:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 133 浏览量
2023-03-28
13:45:44
上传
评论
收藏 714KB ZIP 举报
温馨提示
tinycrypt是一个密码算法库,专注于小型、简单的实现。.zip
资源推荐
资源详情
资源评论
收起资源包目录
tinycrypt是一个密码算法库,专注于小型、简单的实现。.zip (55个子文件)
tinycrypt-master
lib
include
tinycrypt
ecc_dsa.h 6KB
ecc_platform_specific.h 4KB
hmac_prng.h 7KB
aes.h 5KB
ecc.h 20KB
sha256.h 5KB
cmac_mode.h 8KB
cbc_mode.h 7KB
ccm_mode.h 8KB
ctr_prng.h 6KB
constants.h 2KB
ecc_dh.h 5KB
utils.h 4KB
hmac.h 5KB
ctr_mode.h 5KB
Makefile 750B
source
ctr_prng.c 8KB
aes_decrypt.c 6KB
cbc_mode.c 4KB
ecc.c 28KB
ccm_mode.c 8KB
hmac.c 5KB
ctr_mode.c 3KB
hmac_prng.c 7KB
ecc_platform_specific.c 4KB
utils.c 2KB
cmac_mode.c 8KB
ecc_dh.c 7KB
ecc_dsa.c 10KB
aes_encrypt.c 7KB
sha256.c 7KB
README 3KB
documentation
tinycrypt.rst 13KB
Makefile 502B
AUTHORS 360B
LICENSE 3KB
tests
include
test_utils.h 5KB
test_ecc_utils.h 4KB
test_hmac_prng.c 258KB
test_cbc_mode.c 6KB
test_ctr_mode.c 5KB
Makefile 2KB
test_cmac_mode.c 9KB
test_ecc_dsa.c 30KB
test_ctr_prng.c 16KB
test_sha256.c 15KB
test_aes.c 64KB
test_ecc_dh.c 21KB
test_hmac.c 13KB
test_ecc_utils.c 8KB
test_ccm_mode.c 15KB
pseudo-random-data.bin 512KB
config.mk 864B
VERSION 6B
.gitignore 21B
共 55 条
- 1
资源评论
- linminsnail2023-06-06发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 下载安装这个软件.apk
- 【数据集详细解释及案例分析】数据集详细解释及案例分析
- 基于SHT71温湿度传感器、STM32F103C8T6、LCD1602温湿度采集显示系统proteus仿真设计
- 基于TH02温湿度传感器、STM32F103C8T6、LCD1602、FREERTOS的温湿度采集系统proteus仿真设计
- 【TCP-IP协议详细解释及案例分析】TCP-IP协议详细解释及案例分析
- 一文搞懂 LSTM(长短期记忆网络).rar
- 【autosar简介及基本案例解析】autosar简介及基本案例解析
- java模拟斗地主洗牌发牌
- springboot+vue登录系统 vue部分
- 常用常见 SQL语句语法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功