From 3e909da42c76cc1bdb85d6c2caa699d6a00b6229 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Sat, 15 Oct 2022 22:08:59 +0800 Subject: [PATCH] Add Apple RNG --- src/rand_apple.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/rand_apple.c diff --git a/src/rand_apple.c b/src/rand_apple.c new file mode 100644 index 00000000..1c2bb0b8 --- /dev/null +++ b/src/rand_apple.c @@ -0,0 +1,31 @@ +/* + * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ + + +#include +#include +#include +#include +#include +#include // clang -framework Security + + +int rand_bytes(uint8_t *buf, size_t len) +{ + int errCode; + if ((errCode = SecRandomCopyBytes(kSecRandomDefault, len, buf)) != errSecSuccess) { + //CFStringRef errStr; + //errStr = SecCopyErrorMessageString(errCode, NULL); + //CFRelease(errStr); + error_print(); + return -1; + } + return 1; +} +