21 行
742 B
C
21 行
742 B
C
/*
|
|
* randombytes_ios.c — iOS / macOS 随机字节实现
|
|
*
|
|
* 使用 arc4random_buf() 生成密码学安全的随机字节。
|
|
*
|
|
* 选型说明:
|
|
* - arc4random_buf 由苹果 libSystem 提供,底层调用内核级 CSPRNG,
|
|
* 等价于 /dev/urandom 但无需文件句柄,性能更优且无系统调用开销。
|
|
* - Apple 官方推荐用于 iOS/macOS 的密码学随机数生成。
|
|
* - 无需种子初始化,不阻塞,适合在任意上下文(含主线程)调用。
|
|
*
|
|
* 替代了原始 randombytes.c 中的 open("/dev/urandom") 方案。
|
|
*/
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include "randombytes.h"
|
|
|
|
void randombytes(uint8_t *out, size_t outlen) {
|
|
arc4random_buf(out, outlen);
|
|
} |