nss: upgrade to release 3.73
[LibreOffice.git] / include / rtl / digest.h
blob4f6dd13ca6fa04a609ce75453de19441c277ab4f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_RTL_DIGEST_H
21 #define INCLUDED_RTL_DIGEST_H
23 #include "sal/config.h"
25 #include "sal/saldllapi.h"
26 #include "sal/types.h"
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 /** Digest Handle opaque type.
34 typedef void* rtlDigest;
37 /** Digest Algorithm enumeration.
38 @see rtl_digest_create()
40 enum __rtl_DigestAlgorithm
42 rtl_Digest_AlgorithmMD2,
43 rtl_Digest_AlgorithmMD5,
44 rtl_Digest_AlgorithmSHA,
45 rtl_Digest_AlgorithmSHA1,
47 rtl_Digest_AlgorithmHMAC_MD5,
48 rtl_Digest_AlgorithmHMAC_SHA1,
50 rtl_Digest_AlgorithmInvalid,
51 rtl_Digest_Algorithm_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
54 /** Digest Algorithm type.
56 typedef enum __rtl_DigestAlgorithm rtlDigestAlgorithm;
59 /** Error Code enumeration.
61 enum __rtl_DigestError
63 rtl_Digest_E_None,
64 rtl_Digest_E_Argument,
65 rtl_Digest_E_Algorithm,
66 rtl_Digest_E_BufferSize,
67 rtl_Digest_E_Memory,
68 rtl_Digest_E_Unknown,
69 rtl_Digest_E_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
72 /** Error Code type.
74 typedef enum __rtl_DigestError rtlDigestError;
77 /** Create a digest handle for the given algorithm.
78 @see rtlDigestAlgorithm
80 @param[in] Algorithm digest algorithm.
81 @return Digest handle, or 0 upon failure.
83 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_create (
84 rtlDigestAlgorithm Algorithm
85 ) SAL_THROW_EXTERN_C();
88 /** Destroy a digest handle.
89 @post Digest handle destroyed and invalid.
90 @param[in] Digest digest handle to be destroyed.
91 @return None.
93 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroy (
94 rtlDigest Digest
95 ) SAL_THROW_EXTERN_C();
98 /** Query the algorithm of a given digest.
99 @param[in] Digest digest handle.
100 @return digest algorithm, or <code>rtl_Digest_AlgorithmInvalid</code> upon failure.
102 SAL_DLLPUBLIC rtlDigestAlgorithm SAL_CALL rtl_digest_queryAlgorithm (
103 rtlDigest Digest
104 ) SAL_THROW_EXTERN_C();
107 /** Query the length of a given digest.
108 @param[in] Digest digest handle.
109 @return digest length, or 0 upon failure.
111 SAL_DLLPUBLIC sal_uInt32 SAL_CALL rtl_digest_queryLength (
112 rtlDigest Digest
113 ) SAL_THROW_EXTERN_C();
116 /** Initialize a digest with given data.
117 @param[in] Digest digest handle.
118 @param[in] pData data buffer.
119 @param[in] nDatLen data length.
121 @retval rtl_Digest_E_None upon success.
123 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_init (
124 rtlDigest Digest,
125 const sal_uInt8 *pData, sal_uInt32 nDatLen
126 ) SAL_THROW_EXTERN_C();
129 /** Update a digest with given data.
130 @param[in] Digest digest handle.
131 @param[in] pData data buffer.
132 @param[in] nDatLen data length.
134 @retval rtl_Digest_E_None upon success.
136 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_update (
137 rtlDigest Digest,
138 const void *pData, sal_uInt32 nDatLen
139 ) SAL_THROW_EXTERN_C();
142 /** Finalize a digest and retrieve the digest value.
143 @pre Digest value length must not be less than digest length.
144 @post Digest initialized to accept another update sequence.
145 @see rtl_digest_queryLength()
146 @see rtl_digest_update()
148 @param[in] Digest digest handle.
149 @param[in] pBuffer digest value buffer.
150 @param[in] nBufLen digest value length.
152 @retval rtl_Digest_E_None upon success.
154 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_get (
155 rtlDigest Digest,
156 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
157 ) SAL_THROW_EXTERN_C();
159 #define RTL_DIGEST_LENGTH_MD2 16
161 /** Create a MD2 digest handle.
163 The MD2 digest algorithm is specified in
164 RFC 1319 (Informational)
165 The MD2 Message-Digest Algorithm
167 @see rtl_digest_create()
169 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_createMD2 (void) SAL_THROW_EXTERN_C();
172 /** Destroy a MD2 digest handle.
173 @see rtl_digest_destroy()
175 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroyMD2 (
176 rtlDigest Digest
177 ) SAL_THROW_EXTERN_C();
179 /** Update a MD2 digest with given data.
180 @see rtl_digest_update()
182 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_updateMD2 (
183 rtlDigest Digest,
184 const void *pData, sal_uInt32 nDatLen
185 ) SAL_THROW_EXTERN_C();
187 /** Finalize a MD2 digest and retrieve the digest value.
188 @see rtl_digest_get()
190 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_getMD2 (
191 rtlDigest Digest,
192 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
193 ) SAL_THROW_EXTERN_C();
195 /** Evaluate a MD2 digest value from given data.
197 This function performs an optimized call sequence on a
198 single data buffer, avoiding digest creation and destruction.
200 @see rtl_digest_updateMD2()
201 @see rtl_digest_getMD2()
203 @param[in] pData data buffer.
204 @param[in] nDatLen data length.
205 @param[in] pBuffer digest value buffer.
206 @param[in] nBufLen digest value length.
208 @retval rtl_Digest_E_None upon success.
210 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_MD2 (
211 const void *pData, sal_uInt32 nDatLen,
212 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
213 ) SAL_THROW_EXTERN_C();
215 #define RTL_DIGEST_LENGTH_MD5 16
217 /** Create a MD5 digest handle.
219 The MD5 digest algorithm is specified in
220 RFC 1321 (Informational)
221 The MD5 Message-Digest Algorithm
223 @see rtl_digest_create()
225 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_createMD5 (void) SAL_THROW_EXTERN_C();
227 /** Destroy a MD5 digest handle.
228 @see rtl_digest_destroy()
230 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroyMD5 (
231 rtlDigest Digest
232 ) SAL_THROW_EXTERN_C();
234 /** Update a MD5 digest with given data.
235 @see rtl_digest_update()
237 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_updateMD5 (
238 rtlDigest Digest,
239 const void *pData, sal_uInt32 nDatLen
240 ) SAL_THROW_EXTERN_C();
242 /** Finalize a MD5 digest and retrieve the digest value.
243 @see rtl_digest_get()
245 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_getMD5 (
246 rtlDigest Digest,
247 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
248 ) SAL_THROW_EXTERN_C();
250 /** Retrieve the raw (not finalized) MD5 digest value.
252 This function is a non-standard replacement for
253 rtl_digest_getMD5() and must be used with caution.
255 @post Digest initialized to accept another update sequence.
256 @see rtl_digest_get()
258 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_rawMD5 (
259 rtlDigest Digest,
260 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
261 ) SAL_THROW_EXTERN_C();
263 /** Evaluate a MD5 digest value from given data.
265 This function performs an optimized call sequence on a
266 single data buffer, avoiding digest creation and destruction.
268 @see rtl_digest_updateMD5()
269 @see rtl_digest_getMD5()
271 @param[in] pData data buffer.
272 @param[in] nDatLen data length.
273 @param[in] pBuffer digest value buffer.
274 @param[in] nBufLen digest value length.
276 @retval rtl_Digest_E_None upon success.
278 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_MD5 (
279 const void *pData, sal_uInt32 nDatLen,
280 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
281 ) SAL_THROW_EXTERN_C();
283 #define RTL_DIGEST_LENGTH_SHA 20
285 /** Create a SHA digest handle.
287 The SHA digest algorithm is specified in
288 FIPS PUB 180 (Superseded by FIPS PUB 180-1)
289 Secure Hash Standard
291 @deprecated The implementation is buggy and generates incorrect results
292 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
294 @see rtl_digest_create()
296 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_createSHA (void) SAL_THROW_EXTERN_C();
298 /** Destroy a SHA digest handle.
300 @deprecated The implementation is buggy and generates incorrect results
301 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
303 @see rtl_digest_destroy()
305 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroySHA (
306 rtlDigest Digest
307 ) SAL_THROW_EXTERN_C();
310 /** Update a SHA digest with given data.
312 @deprecated The implementation is buggy and generates incorrect results
313 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
315 @see rtl_digest_update()
317 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_updateSHA (
318 rtlDigest Digest,
319 const void *pData, sal_uInt32 nDatLen
320 ) SAL_THROW_EXTERN_C();
322 /** Finalize a SHA digest and retrieve the digest value.
324 @deprecated The implementation is buggy and generates incorrect results
325 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
327 @see rtl_digest_get()
329 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_getSHA (
330 rtlDigest Digest,
331 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
332 ) SAL_THROW_EXTERN_C();
334 /** Evaluate a SHA digest value from given data.
336 This function performs an optimized call sequence on a
337 single data buffer, avoiding digest creation and destruction.
339 @deprecated The implementation is buggy and generates incorrect results
340 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
342 @see rtl_digest_updateSHA()
343 @see rtl_digest_getSHA()
345 @param[in] pData data buffer.
346 @param[in] nDatLen data length.
347 @param[in] pBuffer digest value buffer.
348 @param[in] nBufLen digest value length.
350 @retval rtl_Digest_E_None upon success.
352 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_SHA (
353 const void *pData, sal_uInt32 nDatLen,
354 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
355 ) SAL_THROW_EXTERN_C();
357 /*========================================================================
359 * rtl_digest_SHA1 interface.
361 *======================================================================*/
362 #define RTL_DIGEST_LENGTH_SHA1 20
364 /** Create a SHA1 digest handle.
366 The SHA1 digest algorithm is specified in
367 FIPS PUB 180-1 (Supersedes FIPS PUB 180)
368 Secure Hash Standard
370 @deprecated The implementation is buggy and generates incorrect results
371 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
373 @see rtl_digest_create()
375 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_createSHA1 (void) SAL_THROW_EXTERN_C();
377 /** Destroy a SHA1 digest handle.
379 @deprecated The implementation is buggy and generates incorrect results
380 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
382 @see rtl_digest_destroy()
384 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroySHA1 (
385 rtlDigest Digest
386 ) SAL_THROW_EXTERN_C();
388 /** Update a SHA1 digest with given data.
390 @deprecated The implementation is buggy and generates incorrect results
391 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
393 @see rtl_digest_update()
395 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_updateSHA1 (
396 rtlDigest Digest,
397 const void *pData, sal_uInt32 nDatLen
398 ) SAL_THROW_EXTERN_C();
400 /** Finalize a SHA1 digest and retrieve the digest value.
402 @deprecated The implementation is buggy and generates incorrect results
403 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
405 @see rtl_digest_get()
407 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_getSHA1 (
408 rtlDigest Digest,
409 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
410 ) SAL_THROW_EXTERN_C();
412 /** Evaluate a SHA1 digest value from given data.
414 This function performs an optimized call sequence on a
415 single data buffer, avoiding digest creation and destruction.
417 @deprecated The implementation is buggy and generates incorrect results
418 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
420 @see rtl_digest_updateSHA1()
421 @see rtl_digest_getSHA1()
423 @param[in] pData data buffer.
424 @param[in] nDatLen data length.
425 @param[in] pBuffer digest value buffer.
426 @param[in] nBufLen digest value length.
428 @retval rtl_Digest_E_None upon success.
430 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_SHA1 (
431 const void *pData, sal_uInt32 nDatLen,
432 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
433 ) SAL_THROW_EXTERN_C();
435 #define RTL_DIGEST_LENGTH_HMAC_MD5 RTL_DIGEST_LENGTH_MD5
437 /** Create a HMAC_MD5 digest handle.
439 The HMAC_MD5 digest algorithm is specified in
441 RFC 2104 (Informational)
442 HMAC: Keyed-Hashing for Message Authentication
444 @see rtl_digest_create()
446 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_createHMAC_MD5 (void) SAL_THROW_EXTERN_C();
448 /** Destroy a HMAC_MD5 digest handle.
449 @see rtl_digest_destroy()
451 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroyHMAC_MD5 (
452 rtlDigest Digest
453 ) SAL_THROW_EXTERN_C();
455 /** Initialize a HMAC_MD5 digest.
456 @see rtl_digest_init()
458 @param[in] Digest digest handle.
459 @param[in] pKeyData key material buffer.
460 @param[in] nKeyLen key material length.
462 @retval rtl_Digest_E_None upon success.
464 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_initHMAC_MD5 (
465 rtlDigest Digest,
466 const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen
467 ) SAL_THROW_EXTERN_C();
469 /** Update a HMAC_MD5 digest with given data.
470 @see rtl_digest_update()
472 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_updateHMAC_MD5 (
473 rtlDigest Digest,
474 const void *pData, sal_uInt32 nDatLen
475 ) SAL_THROW_EXTERN_C();
477 /** Finalize a HMAC_MD5 digest and retrieve the digest value.
478 @see rtl_digest_get()
480 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_getHMAC_MD5 (
481 rtlDigest Digest,
482 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
483 ) SAL_THROW_EXTERN_C();
485 /** Evaluate a HMAC_MD5 digest value from given data.
487 This function performs an optimized call sequence on a
488 single data buffer, avoiding digest creation and destruction.
490 @see rtl_digest_initHMAC_MD5()
491 @see rtl_digest_updateHMAC_MD5()
492 @see rtl_digest_getHMAC_MD5()
494 @param[in] pKeyData key material buffer.
495 @param[in] nKeyLen key material length.
496 @param[in] pData data buffer.
497 @param[in] nDatLen data length.
498 @param[in] pBuffer digest value buffer.
499 @param[in] nBufLen digest value length.
501 @retval rtl_Digest_E_None upon success.
503 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_HMAC_MD5 (
504 const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen,
505 const void *pData, sal_uInt32 nDatLen,
506 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
507 ) SAL_THROW_EXTERN_C();
509 #define RTL_DIGEST_LENGTH_HMAC_SHA1 RTL_DIGEST_LENGTH_SHA1
511 /** Create a HMAC_SHA1 digest handle.
513 The HMAC_SHA1 digest algorithm is specified in
514 RFC 2104 (Informational)
515 HMAC: Keyed-Hashing for Message Authentication
516 RFC 2898 (Informational)
517 PKCS #5: Password-Based Cryptography Specification Version 2.0
519 @deprecated The implementation is buggy and generates incorrect results
520 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
522 @see rtl_digest_create()
524 SAL_DLLPUBLIC rtlDigest SAL_CALL rtl_digest_createHMAC_SHA1 (void) SAL_THROW_EXTERN_C();
526 /** Destroy a HMAC_SHA1 digest handle.
528 @deprecated The implementation is buggy and generates incorrect results
529 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
531 @see rtl_digest_destroy()
533 SAL_DLLPUBLIC void SAL_CALL rtl_digest_destroyHMAC_SHA1 (
534 rtlDigest Digest
535 ) SAL_THROW_EXTERN_C();
537 /** Initialize a HMAC_SHA1 digest.
539 @deprecated The implementation is buggy and generates incorrect results
540 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
542 @see rtl_digest_init()
544 @param[in] Digest digest handle.
545 @param[in] pKeyData key material buffer.
546 @param[in] nKeyLen key material length.
548 @retval rtl_Digest_E_None upon success.
550 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_initHMAC_SHA1 (
551 rtlDigest Digest,
552 const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen
553 ) SAL_THROW_EXTERN_C();
555 /** Update a HMAC_SHA1 digest with given data.
557 @deprecated The implementation is buggy and generates incorrect results
558 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
560 @see rtl_digest_update()
562 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_updateHMAC_SHA1 (
563 rtlDigest Digest,
564 const void *pData, sal_uInt32 nDatLen
565 ) SAL_THROW_EXTERN_C();
567 /** Finalize a HMAC_SHA1 digest and retrieve the digest value.
569 @deprecated The implementation is buggy and generates incorrect results
570 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
572 @see rtl_digest_get()
574 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_getHMAC_SHA1 (
575 rtlDigest Digest,
576 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
577 ) SAL_THROW_EXTERN_C();
579 /** Evaluate a HMAC_SHA1 digest value from given data.
581 This function performs an optimized call sequence on a
582 single data buffer, avoiding digest creation and destruction.
584 @deprecated The implementation is buggy and generates incorrect results
585 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
587 @see rtl_digest_initHMAC_SHA1()
588 @see rtl_digest_updateHMAC_SHA1()
589 @see rtl_digest_getHMAC_SHA1()
591 @param[in] pKeyData key material buffer.
592 @param[in] nKeyLen key material length.
593 @param[in] pData data buffer.
594 @param[in] nDatLen data length.
595 @param[in] pBuffer digest value buffer.
596 @param[in] nBufLen digest value length.
598 @retval rtl_Digest_E_None upon success.
600 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_HMAC_SHA1 (
601 const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen,
602 const void *pData, sal_uInt32 nDatLen,
603 sal_uInt8 *pBuffer, sal_uInt32 nBufLen
604 ) SAL_THROW_EXTERN_C();
606 /** Password-Based Key Derivation Function.
608 The PBKDF2 key derivation function is specified in
609 RFC 2898 (Informational)
610 PKCS #5: Password-Based Cryptography Specification Version 2.0
612 @deprecated The implementation is buggy and generates incorrect results
613 for 52 <= (len % 64) <= 55; use only for bug-compatibility
614 or if the input is guaranteed to have a good length
615 by a start-key derivation round.
617 @param[out] pKeyData derived key
618 @param[in] nKeyLen derived key length
619 @param[in] pPassData password
620 @param[in] nPassLen password length
621 @param[in] pSaltData salt
622 @param[in] nSaltLen salt length
623 @param[in] nCount iteration count
625 @retval rtl_Digest_E_None upon success.
627 SAL_DLLPUBLIC rtlDigestError SAL_CALL rtl_digest_PBKDF2 (
628 sal_uInt8 *pKeyData , sal_uInt32 nKeyLen,
629 const sal_uInt8 *pPassData, sal_uInt32 nPassLen,
630 const sal_uInt8 *pSaltData, sal_uInt32 nSaltLen,
631 sal_uInt32 nCount
632 ) SAL_THROW_EXTERN_C();
634 #ifdef __cplusplus
636 #endif
638 #endif // INCLUDED_RTL_DIGEST_H
640 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */