1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsRandomGenerator.h"
7 #include "ScopedNSSTypes.h"
8 #include "nsNSSComponent.h"
13 NS_IMPL_ISUPPORTS(nsRandomGenerator
, nsIRandomGenerator
)
16 nsRandomGenerator::GenerateRandomBytes(uint32_t aLength
, uint8_t** aBuffer
) {
17 NS_ENSURE_ARG_POINTER(aBuffer
);
20 mozilla::UniquePK11SlotInfo
slot(PK11_GetInternalSlot());
22 return NS_ERROR_FAILURE
;
25 auto buf
= static_cast<uint8_t*>(moz_xmalloc(aLength
));
27 SECStatus srv
= PK11_GenerateRandomOnSlot(slot
.get(), buf
, aLength
);
28 if (srv
!= SECSuccess
) {
30 return NS_ERROR_FAILURE
;