netwerk/base/public/nsICryptoHMAC.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 "nsISupports.idl"
michael@0 6 interface nsIInputStream;
michael@0 7 interface nsIKeyObject;
michael@0 8
michael@0 9 /**
michael@0 10 * nsICryptoHMAC
michael@0 11 * This interface provides HMAC signature algorithms.
michael@0 12 */
michael@0 13
michael@0 14 [scriptable, uuid(8FEB4C7C-1641-4a7b-BC6D-1964E2099497)]
michael@0 15 interface nsICryptoHMAC : nsISupports
michael@0 16 {
michael@0 17 /**
michael@0 18 * Hashing Algorithms. These values are to be used by the
michael@0 19 * |init| method to indicate which hashing function to
michael@0 20 * use. These values map onto the values defined in
michael@0 21 * mozilla/security/nss/lib/softoken/pkcs11t.h and are
michael@0 22 * switched to CKM_*_HMAC constant.
michael@0 23 */
michael@0 24 const short MD2 = 1;
michael@0 25 const short MD5 = 2;
michael@0 26 const short SHA1 = 3;
michael@0 27 const short SHA256 = 4;
michael@0 28 const short SHA384 = 5;
michael@0 29 const short SHA512 = 6;
michael@0 30
michael@0 31 /**
michael@0 32 * Initialize the hashing object. This method may be
michael@0 33 * called multiple times with different algorithm types.
michael@0 34 *
michael@0 35 * @param aAlgorithm the algorithm type to be used.
michael@0 36 * This value must be one of the above valid
michael@0 37 * algorithm types.
michael@0 38 *
michael@0 39 * @param aKeyObject
michael@0 40 * Object holding a key. To create the key object use for instance:
michael@0 41 * var keyObject = Components.classes["@mozilla.org/security/keyobjectfactory;1"]
michael@0 42 * .getService(Components.interfaces.nsIKeyObjectFactory)
michael@0 43 * .keyFromString(Components.interfaces.nsIKeyObject.HMAC, rawKeyData);
michael@0 44 *
michael@0 45 * WARNING: This approach is not FIPS compliant.
michael@0 46 *
michael@0 47 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm
michael@0 48 * type is passed.
michael@0 49 *
michael@0 50 * NOTE: This method must be called before any other method
michael@0 51 * on this interface is called.
michael@0 52 */
michael@0 53 void init(in unsigned long aAlgorithm, in nsIKeyObject aKeyObject);
michael@0 54
michael@0 55 /**
michael@0 56 * @param aData a buffer to calculate the hash over
michael@0 57 *
michael@0 58 * @param aLen the length of the buffer |aData|
michael@0 59 *
michael@0 60 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
michael@0 61 * called.
michael@0 62 */
michael@0 63 void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen);
michael@0 64
michael@0 65 /**
michael@0 66 * Calculates and updates a new hash based on a given data stream.
michael@0 67 *
michael@0 68 * @param aStream an input stream to read from.
michael@0 69 *
michael@0 70 * @param aLen how much to read from the given |aStream|. Passing
michael@0 71 * UINT32_MAX indicates that all data available will be used
michael@0 72 * to update the hash.
michael@0 73 *
michael@0 74 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
michael@0 75 * called.
michael@0 76 *
michael@0 77 * @throws NS_ERROR_NOT_AVAILABLE if the requested amount of
michael@0 78 * data to be calculated into the hash is not available.
michael@0 79 *
michael@0 80 */
michael@0 81 void updateFromStream(in nsIInputStream aStream, in unsigned long aLen);
michael@0 82
michael@0 83 /**
michael@0 84 * Completes this HMAC object and produces the actual HMAC diegest data.
michael@0 85 *
michael@0 86 * @param aASCII if true then the returned value is a base-64
michael@0 87 * encoded string. if false, then the returned value is
michael@0 88 * binary data.
michael@0 89 *
michael@0 90 * @return a hash of the data that was read by this object. This can
michael@0 91 * be either binary data or base 64 encoded.
michael@0 92 *
michael@0 93 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
michael@0 94 * called.
michael@0 95 *
michael@0 96 * NOTE: This method may be called any time after |init|
michael@0 97 * is called. This call resets the object to its
michael@0 98 * pre-init state.
michael@0 99 */
michael@0 100 ACString finish(in boolean aASCII);
michael@0 101
michael@0 102 /**
michael@0 103 * Reinitialize HMAC context to be reused with the same
michael@0 104 * settings (the key and hash algorithm) but on different
michael@0 105 * set of data.
michael@0 106 */
michael@0 107 void reset();
michael@0 108 };

mercurial