nsICryptoHMAC.idl 3.7 KB

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