// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Algorithm testing framework and tests.
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
* Copyright (c) 2007 Nokia Siemens Networks
* Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
* Copyright (c) 2019 Google LLC
*
* Updated RFC4106 AES-GCM testing.
* Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
* Adrian Hoban <adrian.hoban@intel.com>
* Gabriele Paoloni <gabriele.paoloni@intel.com>
* Tadeusz Struk (tadeusz.struk@intel.com)
* Copyright (c) 2010, Intel Corporation.
*/
#include <crypto/aead.h>
#include <crypto/hash.h>
#include <crypto/skcipher.h>
#include <linux/err.h>
#include <linux/fips.h>
#include <linux/module.h>
#include <linux/once.h>
#include <linux/random.h>
#include <linux/scatterlist.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uio.h>
#include <crypto/rng.h>
#include <crypto/drbg.h>
#include <crypto/akcipher.h>
#include <crypto/kpp.h>
#include <crypto/acompress.h>
#include <crypto/internal/simd.h>
#include "internal.h"
static bool notests;
module_param(notests, bool, 0644);
MODULE_PARM_DESC(notests, "disable crypto self-tests");
static bool panic_on_fail;
module_param(panic_on_fail, bool, 0444);
#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
static bool noextratests;
module_param(noextratests, bool, 0644);
MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
static unsigned int fuzz_iterations = 100;
module_param(fuzz_iterations, uint, 0644);
MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
#endif
#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
/* a perfect nop */
int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
{
return 0;
}
#else
#include "testmgr.h"
/*
* Need slab memory for testing (size in number of pages).
*/
#define XBUFSIZE 8
/*
* Used by test_cipher()
*/
#define ENCRYPT 1
#define DECRYPT 0
struct aead_test_suite {
const struct aead_testvec *vecs;
unsigned int count;
/*
* Set if trying to decrypt an inauthentic ciphertext with this
* algorithm might result in EINVAL rather than EBADMSG, due to other
* validation the algorithm does on the inputs such as length checks.
*/
unsigned int einval_allowed : 1;
/*
* Set if this algorithm requires that the IV be located at the end of
* the AAD buffer, in addition to being given in the normal way. The
* behavior when the two IV copies differ is implementation-defined.
*/
unsigned int aad_iv : 1;
};
struct cipher_test_suite {
const struct cipher_testvec *vecs;
unsigned int count;
};
struct comp_test_suite {
struct {
const struct comp_testvec *vecs;
unsigned int count;
} comp, decomp;
};
struct hash_test_suite {
const struct hash_testvec *vecs;
unsigned int count;
};
struct cprng_test_suite {
const struct cprng_testvec *vecs;
unsigned int count;
};
struct drbg_test_suite {
const struct drbg_testvec *vecs;
unsigned int count;
};
struct akcipher_test_suite {
const struct akcipher_testvec *vecs;
unsigned int count;
};
struct kpp_test_suite {
const struct kpp_testvec *vecs;
unsigned int count;
};
struct alg_test_desc {
const char *alg;
const char *generic_driver;
int (*test)(const struct alg_test_desc *desc, const char *driver,
u32 type, u32 mask);
int fips_allowed; /* set if alg is allowed in fips mode */
union {
struct aead_test_suite aead;
struct cipher_test_suite cipher;
struct comp_test_suite comp;
struct hash_test_suite hash;
struct cprng_test_suite cprng;
struct drbg_test_suite drbg;
struct akcipher_test_suite akcipher;
struct kpp_test_suite kpp;
} suite;
};
static void hexdump(unsigned char *buf, unsigned int len)
{
print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
16, 1,
buf, len, false);
}
static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
{
int i;
for (i = 0; i < XBUFSIZE; i++) {
buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
if (!buf[i])
goto err_free_buf;
}
return 0;
err_free_buf:
while (i-- > 0)
free_pages((unsigned long)buf[i], order);
return -ENOMEM;
}
static int testmgr_alloc_buf(char *buf[XBUFSIZE])
{
return __testmgr_alloc_buf(buf, 0);
}
static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
{
int i;
for (i = 0; i < XBUFSIZE; i++)
free_pages((unsigned long)buf[i], order);
}
static void testmgr_free_buf(char *buf[XBUFSIZE])
{
__testmgr_free_buf(buf, 0);
}
#define TESTMGR_POISON_BYTE 0xfe
#define TESTMGR_POISON_LEN 16
static inline void testmgr_poison(void *addr, size_t len)
{
memset(addr, TESTMGR_POISON_BYTE, len);
}
/* Is the memory region still fully poisoned? */
static inline bool testmgr_is_poison(const void *addr, size_t len)
{
return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
}
/* flush type for hash algorithms */
enum flush_type {
/* merge with update of previous buffer(s) */
FLUSH_TYPE_NONE = 0,
/* update with previous buffer(s) before doing this one */
FLUSH_TYPE_FLUSH,
/* likewise, but also export and re-import the intermediate state */
FLUSH_TYPE_REIMPORT,
};
/* finalization function for hash algorithms */
enum finalization_type {
FINALIZATION_TYPE_FINAL, /* use final() */
FINALIZATION_TYPE_FINUP, /* use finup() */
FINALIZATION_TYPE_DIGEST, /* use digest() */
};
#define TEST_SG_TOTAL 10000
/**
* struct test_sg_division - description of a scatterlist entry
*
* This struct describes one entry of a scatterlist being constructed to check a
* crypto test vector.
*
* @proportion_of_total: length of this chunk relative to the total length,
* given as a proportion out of TEST_SG_TOTAL so that it
* scales to fit any test vector
* @offset: byte offset into a 2-page buffer at which this chunk will start
* @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
* @offset
* @flush_type: for hashes, whether an update() should be done now vs.
* continuing to accumulate data
* @nosimd: if doing the pending update(), do it with SIMD disabled?
*/
struct test_sg_division {
unsigned int proportion_of_total;
unsigned int offset;
bool offset_relative_to_alignmask;
enum flush_type flush_type;
bool nosimd;
};
/**
* struct testvec_config - configuration for testing a crypto test vector
*
* This struct describes the data layout and other parameters with which each
* crypto test vector can be tested.
*
* @name: name of this config, logged for debugging purposes if a test fails
* @inplace: operate on the data in-place, if applicable for the algorithm type?
* @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
* @src_divs: description of how to arrange the source scatterlist
* @dst_divs: description of how to arrange the dst scatterlist, if applicable
* for the algorithm type. Defaults to @src_divs if unset.
* @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
* where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
* @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
* the @iv_offset
* @key_offset: misalignment of the key, where 0 is default alignment
* @key_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
* the @key_offset
* @finalization_type: what finalization function to use for hashes
* @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
*/
struct testvec_config {
const char *name;
bool inplace;
u32 req_flags;
struct test_sg_division src_divs[XBUFSIZE];
struct test_sg_division dst_divs[XBUFSIZE];
unsigned int iv_offset;
unsigned int key_offset;
bool iv_offset_relative_to_alignmask;
bool key_offset_relative_to_alignmask;
enum finalization_type finalization_type;
bool nosimd;
};
#define TESTVEC_CONFIG_NAM
没有合适的资源?快使用搜索试试~ 我知道了~
基于开源Linux优化的强实时操作系统,可以支持智能汽车.zip
共2000个文件
h:1842个
c:150个
doc:5个
0 下载量 32 浏览量
2024-05-21
06:59:41
上传
评论
收藏 217.76MB ZIP 举报
温馨提示
linux Linux操作系统嵌入了TCP/IP协议栈,协议软件具有路由转发功能。路由转发依赖作为路由器的主机中安装多块网卡,当某一块网卡接收到数据包后,系统内核会根据数据包的目的IP地址,查询路由表,然后根据查询结果将数据包发送到另外一块网卡,最后通过此网卡把数据包发送出去。此主机的处理过程就是路由器完成的核心功能。 通过修改Linux系统内核参数ip_forward的方式实现路由功能,系统使用sysctl命令配置与显示在/proc/sys目录中的内核参数。首先在命令行输入:cat /proc/sys/net/ipv4/ip_forwad,检查Linux内核是不是开启IP转发功能。如果结果为1,表明路由转发功能已经开启;如果结果为0,表明没有开启。出于安全考虑,Linux内核默认是禁止数据包路由转发的。在linux系统中,有临时和永久两种方法启用转发功能。 [3] 临时启用:此种方法只对当前会话起作用,系统重启后不再启用。临时开启的命令格式:sysctl–wnet.ipv4.ip_forward=1。
资源推荐
资源详情
资源评论
收起资源包目录
基于开源Linux优化的强实时操作系统,可以支持智能汽车.zip (2000个子文件)
testmgr.c 145KB
tcrypt.c 78KB
wp512.c 60KB
drbg.c 60KB
aes_generic.c 58KB
streebog_generic.c 58KB
khazad.c 52KB
ecc.c 39KB
twofish_common.c 37KB
camellia_generic.c 34KB
tgr192.c 30KB
gcm.c 30KB
algapi.c 30KB
cryptd.c 28KB
anubis.c 28KB
af_alg.c 26KB
jitterentropy.c 25KB
skcipher.c 25KB
ccm.c 23KB
asym_tpm.c 22KB
serpent_generic.c 21KB
cast5_generic.c 20KB
adiantum.c 19KB
vmac.c 19KB
fcrypt.c 18KB
essiv.c 18KB
chacha20poly1305.c 18KB
x509_cert_parser.c 17KB
rsa-pkcs1pad.c 17KB
seed.c 17KB
async_raid6_recov.c 16KB
pkcs7_parser.c 16KB
asymmetric_type.c 16KB
ahash.c 16KB
algif_aead.c 16KB
blowfish_common.c 16KB
shash.c 16KB
crypto_engine.c 15KB
authencesn.c 14KB
api.c 14KB
simd.c 13KB
pkcs7_verify.c 13KB
aegis128-core.c 13KB
authenc.c 13KB
cast_common.c 13KB
async_pq.c 13KB
rmd320.c 13KB
gf128mul.c 12KB
rmd160.c 12KB
async_xor.c 12KB
crypto_user_base.c 12KB
xts.c 12KB
cts.c 12KB
verify_pefile.c 11KB
ansi_cprng.c 11KB
lrw.c 11KB
rmd256.c 10KB
rmd128.c 10KB
public_key.c 10KB
sm2.c 10KB
crypto_user_stat.c 10KB
algif_skcipher.c 10KB
ctr.c 9KB
keywrap.c 9KB
algif_hash.c 9KB
blake2b_generic.c 9KB
pcrypt.c 9KB
cast6_generic.c 9KB
algif_rng.c 8KB
ecrdsa.c 8KB
sha3_generic.c 8KB
restrict.c 8KB
sha512_generic.c 8KB
nhpoly1305.c 8KB
deflate.c 8KB
cmac.c 8KB
md5.c 7KB
aead.c 7KB
async_tx.c 7KB
scompress.c 7KB
xcbc.c 7KB
tea.c 6KB
hmac.c 6KB
aegis128-neon-inner.c 6KB
x509_public_key.c 6KB
jitterentropy-kcapi.c 6KB
sm4_generic.c 6KB
cfb.c 6KB
raid6test.c 6KB
salsa20_generic.c 6KB
md4.c 6KB
algboss.c 6KB
twofish_generic.c 6KB
dh.c 5KB
crypto_null.c 5KB
rsa.c 5KB
cbc.c 5KB
zstd.c 5KB
ghash-generic.c 5KB
rng.c 5KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
野生的狒狒
- 粉丝: 3393
- 资源: 2436
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功