]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/feeRandom.c
1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
11 * FeeRandom.c - generic, portable random number generator object
16 * Changed to compile with C++.
18 * Eliminated predictability of bytes 4 thru 15 of random data
20 * Reduced size of per-instance giants from 128 to 32 shorts
22 * Created, based on Blaine Garst's NSRandomNumberGenerator class
25 #include "feeRandom.h"
27 #include <Security/SecRandom.h>
29 feeRand
feeRandAllocWithSeed(__attribute__((unused
)) unsigned seed
)
34 feeRand
feeRandAlloc(void)
39 void feeRandFree(__attribute__((unused
)) feeRand frand
)
44 unsigned feeRandNextNum(feeRand frand
)
48 feeRandBytes(frand
, &rand
, sizeof(rand
));
53 void feeRandBytes(__attribute__((unused
)) feeRand frand
, void *bytes
, unsigned numBytes
)
57 err
= SecRandomCopyBytes(kSecRandomDefault
, numBytes
, bytes
);
58 if (err
!= errSecSuccess
) {
59 CKRaise("feeRandBytes");
63 /* new function, 5 March 1999 - dmitch */
64 void feeRandAddEntropy(__attribute__((unused
)) feeRand frand
, __attribute__((unused
)) unsigned entropy
)