1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Doug Turner <dougt@meer.net>.
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
22 * Doug Turner <dougt@meer.net>
23 * Honza Bambas <honzab@firemni.cz>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include
"nsISupports.idl"
40 interface nsIInputStream
;
41 interface nsIKeyObject
;
45 * This interface provides HMAC signature algorithms.
48 [scriptable
, uuid(8FEB4C7C
-1641-4a7b
-BC6D
-1964E2099497
)]
49 interface nsICryptoHMAC
: nsISupports
52 * Hashing Algorithms. These values are to be used by the
53 * |init| method to indicate which hashing function to
54 * use. These values map onto the values defined in
55 * mozilla/security/nss/lib/softoken/pkcs11t.h and are
56 * switched to CKM_*_HMAC constant.
61 const short SHA256
= 4;
62 const short SHA384
= 5;
63 const short SHA512
= 6;
66 * Initialize the hashing object. This method may be
67 * called multiple times with different algorithm types.
69 * @param aAlgorithm the algorithm type to be used.
70 * This value must be one of the above valid
74 * Object holding a key. To create the key object use for instance:
75 * var keyObject = Components.classes["@mozilla.org/security/keyobjectfactory;1"]
76 * .getService(Components.interfaces.nsIKeyObjectFactory)
77 * .keyFromString(Components.interfaces.nsIKeyObject.HMAC, rawKeyData);
79 * WARNING: This approach is not FIPS compliant.
81 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm
84 * NOTE: This method must be called before any other method
85 * on this interface is called.
87 void init
(in unsigned long aAlgorithm
, in nsIKeyObject aKeyObject
);
90 * @param aData a buffer to calculate the hash over
92 * @param aLen the length of the buffer |aData|
94 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
97 void update
([const, array
, size_is(aLen
)] in octet aData
, in unsigned long aLen
);
100 * Calculates and updates a new hash based on a given data stream.
102 * @param aStream an input stream to read from.
104 * @param aLen how much to read from the given |aStream|. Passing
105 * PR_UINT32_MAX indicates that all data available will be used
106 * to update the hash.
108 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
111 * @throws NS_ERROR_NOT_AVAILABLE if the requested amount of
112 * data to be calculated into the hash is not available.
115 void updateFromStream
(in nsIInputStream aStream
, in unsigned long aLen
);
118 * Completes this HMAC object and produces the actual HMAC diegest data.
120 * @param aASCII if true then the returned value is a base-64
121 * encoded string. if false, then the returned value is
124 * @return a hash of the data that was read by this object. This can
125 * be either binary data or base 64 encoded.
127 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
130 * NOTE: This method may be called any time after |init|
131 * is called. This call resets the object to its
134 ACString finish
(in PRBool aASCII
);
137 * Reinitialize HMAC context to be reused with the same
138 * settings (the key and hash algorithm) but on different