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 IRC (such as one of these permanent autoconfirmed members).

Crypto

From WHATWG Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

[NoInterfaceObject]
interface Crypto {
  void getRandomValues(in ArrayBufferView array);
};

[Suplemental, NoInterfaceObject]
interface Window {
  readonly attribute Crypto crypto;
};

Methods

getRandomValues

The getRandomValues method fills array with random data. Specifically, if array is an ArrayBufferView of an integer type (i.e., Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, or Uint32Array), then all the elements of array are overwritten with cryptographically random values of the appropriate type. If array is not of an integer type, getRandomValues throws a TYPE_MISMATCH_ERR. If insufficient cryptographically random values are available, getRandomValues does not alter array and throws a NOT_SUPPORTED_ERR.