security/manager/ssl/src/nsRandomGenerator.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsRandomGenerator.h"
michael@0 6 #include "pk11pub.h"
michael@0 7 #include "secerr.h"
michael@0 8 #include "prerror.h"
michael@0 9 #include "nsNSSComponent.h"
michael@0 10
michael@0 11 ////////////////////////////////////////////////////////////////////////////////
michael@0 12 //// nsRandomGenerator
michael@0 13
michael@0 14 NS_IMPL_ISUPPORTS(nsRandomGenerator, nsIRandomGenerator)
michael@0 15
michael@0 16 ////////////////////////////////////////////////////////////////////////////////
michael@0 17 //// nsIRandomGenerator
michael@0 18
michael@0 19 /* void generateRandomBytes(in unsigned long aLength,
michael@0 20 [retval, array, size_is(aLength)] out octet aBuffer) */
michael@0 21 NS_IMETHODIMP
michael@0 22 nsRandomGenerator::GenerateRandomBytes(uint32_t aLength,
michael@0 23 uint8_t **aBuffer)
michael@0 24 {
michael@0 25 NS_ENSURE_ARG_POINTER(aBuffer);
michael@0 26 *aBuffer = nullptr;
michael@0 27
michael@0 28 mozilla::ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
michael@0 29 if (!slot) {
michael@0 30 return NS_ERROR_FAILURE;
michael@0 31 }
michael@0 32
michael@0 33 uint8_t *buf = reinterpret_cast<uint8_t *>(NS_Alloc(aLength));
michael@0 34 if (!buf) {
michael@0 35 return NS_ERROR_OUT_OF_MEMORY;
michael@0 36 }
michael@0 37
michael@0 38 SECStatus srv = PK11_GenerateRandomOnSlot(slot, buf, aLength);
michael@0 39
michael@0 40 if (SECSuccess != srv) {
michael@0 41 NS_Free(buf);
michael@0 42 return NS_ERROR_FAILURE;
michael@0 43 }
michael@0 44
michael@0 45 *aBuffer = buf;
michael@0 46
michael@0 47 return NS_OK;
michael@0 48 }

mercurial