A user account is required in order to edit this wiki, but we've had to disable public user registrations due to spam.

To request an account, ask an autoconfirmed user on Chat (such as one of these permanent autoconfirmed members).

Crypto: Difference between revisions

From WHATWG Wiki
Jump to navigation Jump to search
(Throw an exception for overlarge arrays, as discussed in https://bugzilla.mozilla.org/show_bug.cgi?id=440046)
Line 12: Line 12:


<pre>interface Crypto {
<pre>interface Crypto {
   void getRandomValues(in ArrayBufferView array);
   ArrayBufferView getRandomValues(in ArrayBufferView array);
};
};


Line 23: Line 23:
# If <var>array</var>'s length is greater than 65536, [http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw throw] a [http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#quotaexceedederror QuotaExceededError] and abort these steps.
# If <var>array</var>'s length is greater than 65536, [http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-throw throw] a [http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#quotaexceedederror QuotaExceededError] and abort these steps.
# Overwrite all elements of <var>array</var> with [[#concept-cryptographically-random-values|cryptographically random values]] of the appropriate type.
# Overwrite all elements of <var>array</var> with [[#concept-cryptographically-random-values|cryptographically random values]] of the appropriate type.
# Return <var>array</var>.


[[Category:Proposals]]
[[Category:Proposals]]

Revision as of 04:17, 21 February 2012

Overview

This document describes a proposal for the window.crypto API.

Definitions

Cryptographically Random Values

A cryptographically random value is a value generated from a cryptographically strong pseudo-random number generator seeded with truly random values. In practice, implementations should generate cryptographically random values using well-established cryptographic pseudo-random number generators, such as RC4, seeded with high-quality entropy, such as from an operating-system entropy source (e.g., /dev/urandom). This document provides no lower-bound on the information theoretic entropy present in cryptographically random values, but implementations should make a best effort to provide as much entropy as practicable.

Interface Crypto

interface Crypto {
  ArrayBufferView getRandomValues(in ArrayBufferView array);
};

partial interface Window {
  readonly attribute Crypto crypto;
};

The getRandomValues(array) must run the following steps:

  1. array is an ArrayBufferView. If array is not of an integer type (i.e., Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, or Uint32Array), throw a TypeMismatchError and abort these steps.
  2. If array's length is greater than 65536, throw a QuotaExceededError and abort these steps.
  3. Overwrite all elements of array with cryptographically random values of the appropriate type.
  4. Return array.