michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: interface nsIInputStream; michael@0: interface nsIKeyObject; michael@0: michael@0: /** michael@0: * nsICryptoHMAC michael@0: * This interface provides HMAC signature algorithms. michael@0: */ michael@0: michael@0: [scriptable, uuid(8FEB4C7C-1641-4a7b-BC6D-1964E2099497)] michael@0: interface nsICryptoHMAC : nsISupports michael@0: { michael@0: /** michael@0: * Hashing Algorithms. These values are to be used by the michael@0: * |init| method to indicate which hashing function to michael@0: * use. These values map onto the values defined in michael@0: * mozilla/security/nss/lib/softoken/pkcs11t.h and are michael@0: * switched to CKM_*_HMAC constant. michael@0: */ michael@0: const short MD2 = 1; michael@0: const short MD5 = 2; michael@0: const short SHA1 = 3; michael@0: const short SHA256 = 4; michael@0: const short SHA384 = 5; michael@0: const short SHA512 = 6; michael@0: michael@0: /** michael@0: * Initialize the hashing object. This method may be michael@0: * called multiple times with different algorithm types. michael@0: * michael@0: * @param aAlgorithm the algorithm type to be used. michael@0: * This value must be one of the above valid michael@0: * algorithm types. michael@0: * michael@0: * @param aKeyObject michael@0: * Object holding a key. To create the key object use for instance: michael@0: * var keyObject = Components.classes["@mozilla.org/security/keyobjectfactory;1"] michael@0: * .getService(Components.interfaces.nsIKeyObjectFactory) michael@0: * .keyFromString(Components.interfaces.nsIKeyObject.HMAC, rawKeyData); michael@0: * michael@0: * WARNING: This approach is not FIPS compliant. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm michael@0: * type is passed. michael@0: * michael@0: * NOTE: This method must be called before any other method michael@0: * on this interface is called. michael@0: */ michael@0: void init(in unsigned long aAlgorithm, in nsIKeyObject aKeyObject); michael@0: michael@0: /** michael@0: * @param aData a buffer to calculate the hash over michael@0: * michael@0: * @param aLen the length of the buffer |aData| michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been michael@0: * called. michael@0: */ michael@0: void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen); michael@0: michael@0: /** michael@0: * Calculates and updates a new hash based on a given data stream. michael@0: * michael@0: * @param aStream an input stream to read from. michael@0: * michael@0: * @param aLen how much to read from the given |aStream|. Passing michael@0: * UINT32_MAX indicates that all data available will be used michael@0: * to update the hash. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been michael@0: * called. michael@0: * michael@0: * @throws NS_ERROR_NOT_AVAILABLE if the requested amount of michael@0: * data to be calculated into the hash is not available. michael@0: * michael@0: */ michael@0: void updateFromStream(in nsIInputStream aStream, in unsigned long aLen); michael@0: michael@0: /** michael@0: * Completes this HMAC object and produces the actual HMAC diegest data. michael@0: * michael@0: * @param aASCII if true then the returned value is a base-64 michael@0: * encoded string. if false, then the returned value is michael@0: * binary data. michael@0: * michael@0: * @return a hash of the data that was read by this object. This can michael@0: * be either binary data or base 64 encoded. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been michael@0: * called. michael@0: * michael@0: * NOTE: This method may be called any time after |init| michael@0: * is called. This call resets the object to its michael@0: * pre-init state. michael@0: */ michael@0: ACString finish(in boolean aASCII); michael@0: michael@0: /** michael@0: * Reinitialize HMAC context to be reused with the same michael@0: * settings (the key and hash algorithm) but on different michael@0: * set of data. michael@0: */ michael@0: void reset(); michael@0: };