1 Star 0 Fork 0

ForkedRepositories/putty

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
smallprimes.c 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
Simon Tatham 提交于 2020-02-23 22:08 +08:00 . Move init_primes_array out into its own file.
/*
* smallprimes.c: implementation of the array of small primes defined
* in sshkeygen.h.
*/
#include <assert.h>
#include "ssh.h"
#include "sshkeygen.h"
/* The real array that stores the primes. It has to be writable in
* this module, but outside this module, we only expose the
* const-qualified pointer 'smallprimes' so that nobody else can
* accidentally overwrite it. */
static unsigned short smallprimes_array[NSMALLPRIMES];
const unsigned short *const smallprimes = smallprimes_array;
void init_smallprimes(void)
{
if (smallprimes_array[0])
return; /* already done */
bool A[65536];
for (size_t i = 2; i < lenof(A); i++)
A[i] = true;
for (size_t i = 2; i < lenof(A); i++) {
if (!A[i])
continue;
for (size_t j = 2*i; j < lenof(A); j += i)
A[j] = false;
}
size_t pos = 0;
for (size_t i = 2; i < lenof(A); i++) {
if (A[i]) {
assert(pos < NSMALLPRIMES);
smallprimes_array[pos++] = i;
}
}
assert(pos == NSMALLPRIMES);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/forked/putty.git
git@gitee.com:forked/putty.git
forked
putty
putty
master

搜索帮助