1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_RTL_DIGEST_H
25 #define INCLUDED_RTL_DIGEST_H
27 #include "sal/config.h"
29 #include "sal/saldllapi.h"
30 #include "sal/types.h"
36 /** Digest Handle opaque type.
38 typedef void* rtlDigest
;
41 /** Digest Algorithm enumeration.
42 @see rtl_digest_create()
44 enum __rtl_DigestAlgorithm
46 rtl_Digest_AlgorithmMD2
,
47 rtl_Digest_AlgorithmMD5
,
48 rtl_Digest_AlgorithmSHA
,
49 rtl_Digest_AlgorithmSHA1
,
51 rtl_Digest_AlgorithmHMAC_MD5
,
52 rtl_Digest_AlgorithmHMAC_SHA1
,
54 rtl_Digest_AlgorithmInvalid
,
55 rtl_Digest_Algorithm_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
58 /** Digest Algorithm type.
60 typedef enum __rtl_DigestAlgorithm rtlDigestAlgorithm
;
63 /** Error Code enumeration.
65 enum __rtl_DigestError
68 rtl_Digest_E_Argument
,
69 rtl_Digest_E_Algorithm
,
70 rtl_Digest_E_BufferSize
,
73 rtl_Digest_E_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
78 typedef enum __rtl_DigestError rtlDigestError
;
81 /** Create a digest handle for the given algorithm.
82 @see rtlDigestAlgorithm
84 @param[in] Algorithm digest algorithm.
85 @return Digest handle, or 0 upon failure.
87 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_create (
88 rtlDigestAlgorithm Algorithm
89 ) SAL_THROW_EXTERN_C();
92 /** Destroy a digest handle.
93 @post Digest handle destroyed and invalid.
94 @param[in] Digest digest handle to be destroyed.
96 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroy (
98 ) SAL_THROW_EXTERN_C();
101 /** Query the algorithm of a given digest.
102 @param[in] Digest digest handle.
103 @return digest algorithm, or <code>rtl_Digest_AlgorithmInvalid</code> upon failure.
105 SAL_DLLPUBLIC rtlDigestAlgorithm SAL_CALL
rtl_digest_queryAlgorithm (
107 ) SAL_THROW_EXTERN_C();
110 /** Query the length of a given digest.
111 @param[in] Digest digest handle.
112 @return digest length, or 0 upon failure.
114 SAL_DLLPUBLIC sal_uInt32 SAL_CALL
rtl_digest_queryLength (
116 ) SAL_THROW_EXTERN_C();
119 /** Initialize a digest with given data.
120 @param[in] Digest digest handle.
121 @param[in] pData data buffer.
122 @param[in] nDatLen data length.
124 @retval rtl_Digest_E_None upon success.
126 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_init (
128 const sal_uInt8
*pData
, sal_uInt32 nDatLen
129 ) SAL_THROW_EXTERN_C();
132 /** Update a digest with given data.
133 @param[in] Digest digest handle.
134 @param[in] pData data buffer.
135 @param[in] nDatLen data length.
137 @retval rtl_Digest_E_None upon success.
139 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_update (
141 const void *pData
, sal_uInt32 nDatLen
142 ) SAL_THROW_EXTERN_C();
145 /** Finalize a digest and retrieve the digest value.
146 @pre Digest value length must not be less than digest length.
147 @post Digest initialized to accept another update sequence.
148 @see rtl_digest_queryLength()
149 @see rtl_digest_update()
151 @param[in] Digest digest handle.
152 @param[in] pBuffer digest value buffer.
153 @param[in] nBufLen digest value length.
155 @retval rtl_Digest_E_None upon success.
157 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_get (
159 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
160 ) SAL_THROW_EXTERN_C();
162 #define RTL_DIGEST_LENGTH_MD2 16
164 /** Create a MD2 digest handle.
166 The MD2 digest algorithm is specified in
167 RFC 1319 (Informational)
168 The MD2 Message-Digest Algorithm
170 @see rtl_digest_create()
172 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_createMD2 (void) SAL_THROW_EXTERN_C();
175 /** Destroy a MD2 digest handle.
176 @see rtl_digest_destroy()
178 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroyMD2 (
180 ) SAL_THROW_EXTERN_C();
182 /** Update a MD2 digest with given data.
183 @see rtl_digest_update()
185 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_updateMD2 (
187 const void *pData
, sal_uInt32 nDatLen
188 ) SAL_THROW_EXTERN_C();
190 /** Finalize a MD2 digest and retrieve the digest value.
191 @see rtl_digest_get()
193 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_getMD2 (
195 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
196 ) SAL_THROW_EXTERN_C();
198 /** Evaluate a MD2 digest value from given data.
200 This function performs an optimized call sequence on a
201 single data buffer, avoiding digest creation and destruction.
203 @see rtl_digest_updateMD2()
204 @see rtl_digest_getMD2()
206 @param[in] pData data buffer.
207 @param[in] nDatLen data length.
208 @param[in] pBuffer digest value buffer.
209 @param[in] nBufLen digest value length.
211 @retval rtl_Digest_E_None upon success.
213 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_MD2 (
214 const void *pData
, sal_uInt32 nDatLen
,
215 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
216 ) SAL_THROW_EXTERN_C();
218 #define RTL_DIGEST_LENGTH_MD5 16
220 /** Create a MD5 digest handle.
222 The MD5 digest algorithm is specified in
223 RFC 1321 (Informational)
224 The MD5 Message-Digest Algorithm
226 @see rtl_digest_create()
228 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_createMD5 (void) SAL_THROW_EXTERN_C();
230 /** Destroy a MD5 digest handle.
231 @see rtl_digest_destroy()
233 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroyMD5 (
235 ) SAL_THROW_EXTERN_C();
237 /** Update a MD5 digest with given data.
238 @see rtl_digest_update()
240 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_updateMD5 (
242 const void *pData
, sal_uInt32 nDatLen
243 ) SAL_THROW_EXTERN_C();
245 /** Finalize a MD5 digest and retrieve the digest value.
246 @see rtl_digest_get()
248 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_getMD5 (
250 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
251 ) SAL_THROW_EXTERN_C();
253 /** Retrieve the raw (not finalized) MD5 digest value.
255 This function is a non-standard replacement for
256 rtl_digest_getMD5() and must be used with caution.
258 @post Digest initialized to accept another update sequence.
259 @see rtl_digest_get()
261 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_rawMD5 (
263 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
264 ) SAL_THROW_EXTERN_C();
266 /** Evaluate a MD5 digest value from given data.
268 This function performs an optimized call sequence on a
269 single data buffer, avoiding digest creation and destruction.
271 @see rtl_digest_updateMD5()
272 @see rtl_digest_getMD5()
274 @param[in] pData data buffer.
275 @param[in] nDatLen data length.
276 @param[in] pBuffer digest value buffer.
277 @param[in] nBufLen digest value length.
279 @retval rtl_Digest_E_None upon success.
281 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_MD5 (
282 const void *pData
, sal_uInt32 nDatLen
,
283 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
284 ) SAL_THROW_EXTERN_C();
286 #define RTL_DIGEST_LENGTH_SHA 20
288 /** Create a SHA digest handle.
290 The SHA digest algorithm is specified in
291 FIPS PUB 180 (Superseded by FIPS PUB 180-1)
294 @deprecated The implementation is buggy and generates incorrect results
295 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
297 @see rtl_digest_create()
299 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_createSHA (void) SAL_THROW_EXTERN_C();
301 /** Destroy a SHA digest handle.
303 @deprecated The implementation is buggy and generates incorrect results
304 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
306 @see rtl_digest_destroy()
308 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroySHA (
310 ) SAL_THROW_EXTERN_C();
313 /** Update a SHA digest with given data.
315 @deprecated The implementation is buggy and generates incorrect results
316 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
318 @see rtl_digest_update()
320 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_updateSHA (
322 const void *pData
, sal_uInt32 nDatLen
323 ) SAL_THROW_EXTERN_C();
325 /** Finalize a SHA digest and retrieve the digest value.
327 @deprecated The implementation is buggy and generates incorrect results
328 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
330 @see rtl_digest_get()
332 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_getSHA (
334 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
335 ) SAL_THROW_EXTERN_C();
337 /** Evaluate a SHA digest value from given data.
339 This function performs an optimized call sequence on a
340 single data buffer, avoiding digest creation and destruction.
342 @deprecated The implementation is buggy and generates incorrect results
343 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
345 @see rtl_digest_updateSHA()
346 @see rtl_digest_getSHA()
348 @param[in] pData data buffer.
349 @param[in] nDatLen data length.
350 @param[in] pBuffer digest value buffer.
351 @param[in] nBufLen digest value length.
353 @retval rtl_Digest_E_None upon success.
355 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_SHA (
356 const void *pData
, sal_uInt32 nDatLen
,
357 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
358 ) SAL_THROW_EXTERN_C();
360 /*========================================================================
362 * rtl_digest_SHA1 interface.
364 *======================================================================*/
365 #define RTL_DIGEST_LENGTH_SHA1 20
367 /** Create a SHA1 digest handle.
369 The SHA1 digest algorithm is specified in
370 FIPS PUB 180-1 (Supersedes FIPS PUB 180)
373 @deprecated The implementation is buggy and generates incorrect results
374 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
376 @see rtl_digest_create()
378 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_createSHA1 (void) SAL_THROW_EXTERN_C();
380 /** Destroy a SHA1 digest handle.
382 @deprecated The implementation is buggy and generates incorrect results
383 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
385 @see rtl_digest_destroy()
387 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroySHA1 (
389 ) SAL_THROW_EXTERN_C();
391 /** Update a SHA1 digest with given data.
393 @deprecated The implementation is buggy and generates incorrect results
394 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
396 @see rtl_digest_update()
398 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_updateSHA1 (
400 const void *pData
, sal_uInt32 nDatLen
401 ) SAL_THROW_EXTERN_C();
403 /** Finalize a SHA1 digest and retrieve the digest value.
405 @deprecated The implementation is buggy and generates incorrect results
406 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
408 @see rtl_digest_get()
410 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_getSHA1 (
412 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
413 ) SAL_THROW_EXTERN_C();
415 /** Evaluate a SHA1 digest value from given data.
417 This function performs an optimized call sequence on a
418 single data buffer, avoiding digest creation and destruction.
420 @deprecated The implementation is buggy and generates incorrect results
421 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
423 @see rtl_digest_updateSHA1()
424 @see rtl_digest_getSHA1()
426 @param[in] pData data buffer.
427 @param[in] nDatLen data length.
428 @param[in] pBuffer digest value buffer.
429 @param[in] nBufLen digest value length.
431 @retval rtl_Digest_E_None upon success.
433 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_SHA1 (
434 const void *pData
, sal_uInt32 nDatLen
,
435 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
436 ) SAL_THROW_EXTERN_C();
438 #define RTL_DIGEST_LENGTH_HMAC_MD5 RTL_DIGEST_LENGTH_MD5
440 /** Create a HMAC_MD5 digest handle.
442 The HMAC_MD5 digest algorithm is specified in
444 RFC 2104 (Informational)
445 HMAC: Keyed-Hashing for Message Authentication
447 @see rtl_digest_create()
449 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_createHMAC_MD5 (void) SAL_THROW_EXTERN_C();
451 /** Destroy a HMAC_MD5 digest handle.
452 @see rtl_digest_destroy()
454 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroyHMAC_MD5 (
456 ) SAL_THROW_EXTERN_C();
458 /** Initialize a HMAC_MD5 digest.
459 @see rtl_digest_init()
461 @param[in] Digest digest handle.
462 @param[in] pKeyData key material buffer.
463 @param[in] nKeyLen key material length.
465 @retval rtl_Digest_E_None upon success.
467 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_initHMAC_MD5 (
469 const sal_uInt8
*pKeyData
, sal_uInt32 nKeyLen
470 ) SAL_THROW_EXTERN_C();
472 /** Update a HMAC_MD5 digest with given data.
473 @see rtl_digest_update()
475 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_updateHMAC_MD5 (
477 const void *pData
, sal_uInt32 nDatLen
478 ) SAL_THROW_EXTERN_C();
480 /** Finalize a HMAC_MD5 digest and retrieve the digest value.
481 @see rtl_digest_get()
483 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_getHMAC_MD5 (
485 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
486 ) SAL_THROW_EXTERN_C();
488 /** Evaluate a HMAC_MD5 digest value from given data.
490 This function performs an optimized call sequence on a
491 single data buffer, avoiding digest creation and destruction.
493 @see rtl_digest_initHMAC_MD5()
494 @see rtl_digest_updateHMAC_MD5()
495 @see rtl_digest_getHMAC_MD5()
497 @param[in] pKeyData key material buffer.
498 @param[in] nKeyLen key material length.
499 @param[in] pData data buffer.
500 @param[in] nDatLen data length.
501 @param[in] pBuffer digest value buffer.
502 @param[in] nBufLen digest value length.
504 @retval rtl_Digest_E_None upon success.
506 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_HMAC_MD5 (
507 const sal_uInt8
*pKeyData
, sal_uInt32 nKeyLen
,
508 const void *pData
, sal_uInt32 nDatLen
,
509 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
510 ) SAL_THROW_EXTERN_C();
512 #define RTL_DIGEST_LENGTH_HMAC_SHA1 RTL_DIGEST_LENGTH_SHA1
514 /** Create a HMAC_SHA1 digest handle.
516 The HMAC_SHA1 digest algorithm is specified in
517 RFC 2104 (Informational)
518 HMAC: Keyed-Hashing for Message Authentication
519 RFC 2898 (Informational)
520 PKCS #5: Password-Based Cryptography Specification Version 2.0
522 @deprecated The implementation is buggy and generates incorrect results
523 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
525 @see rtl_digest_create()
527 SAL_DLLPUBLIC rtlDigest SAL_CALL
rtl_digest_createHMAC_SHA1 (void) SAL_THROW_EXTERN_C();
529 /** Destroy a HMAC_SHA1 digest handle.
531 @deprecated The implementation is buggy and generates incorrect results
532 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
534 @see rtl_digest_destroy()
536 SAL_DLLPUBLIC
void SAL_CALL
rtl_digest_destroyHMAC_SHA1 (
538 ) SAL_THROW_EXTERN_C();
540 /** Initialize a HMAC_SHA1 digest.
542 @deprecated The implementation is buggy and generates incorrect results
543 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
545 @see rtl_digest_init()
547 @param[in] Digest digest handle.
548 @param[in] pKeyData key material buffer.
549 @param[in] nKeyLen key material length.
551 @retval rtl_Digest_E_None upon success.
553 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_initHMAC_SHA1 (
555 const sal_uInt8
*pKeyData
, sal_uInt32 nKeyLen
556 ) SAL_THROW_EXTERN_C();
558 /** Update a HMAC_SHA1 digest with given data.
560 @deprecated The implementation is buggy and generates incorrect results
561 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
563 @see rtl_digest_update()
565 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_updateHMAC_SHA1 (
567 const void *pData
, sal_uInt32 nDatLen
568 ) SAL_THROW_EXTERN_C();
570 /** Finalize a HMAC_SHA1 digest and retrieve the digest value.
572 @deprecated The implementation is buggy and generates incorrect results
573 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
575 @see rtl_digest_get()
577 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_getHMAC_SHA1 (
579 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
580 ) SAL_THROW_EXTERN_C();
582 /** Evaluate a HMAC_SHA1 digest value from given data.
584 This function performs an optimized call sequence on a
585 single data buffer, avoiding digest creation and destruction.
587 @deprecated The implementation is buggy and generates incorrect results
588 for 52 <= (len % 64) <= 55; use only for bug-compatibility.
590 @see rtl_digest_initHMAC_SHA1()
591 @see rtl_digest_updateHMAC_SHA1()
592 @see rtl_digest_getHMAC_SHA1()
594 @param[in] pKeyData key material buffer.
595 @param[in] nKeyLen key material length.
596 @param[in] pData data buffer.
597 @param[in] nDatLen data length.
598 @param[in] pBuffer digest value buffer.
599 @param[in] nBufLen digest value length.
601 @retval rtl_Digest_E_None upon success.
603 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_HMAC_SHA1 (
604 const sal_uInt8
*pKeyData
, sal_uInt32 nKeyLen
,
605 const void *pData
, sal_uInt32 nDatLen
,
606 sal_uInt8
*pBuffer
, sal_uInt32 nBufLen
607 ) SAL_THROW_EXTERN_C();
609 /** Password-Based Key Derivation Function.
611 The PBKDF2 key derivation function is specified in
612 RFC 2898 (Informational)
613 PKCS #5: Password-Based Cryptography Specification Version 2.0
615 @deprecated The implementation is buggy and generates incorrect results
616 for 52 <= (len % 64) <= 55; use only for bug-compatibility
617 or if the input is guaranteed to have a good length
618 by a start-key derivation round.
620 @param[out] pKeyData derived key
621 @param[in] nKeyLen derived key length
622 @param[in] pPassData password
623 @param[in] nPassLen password length
624 @param[in] pSaltData salt
625 @param[in] nSaltLen salt length
626 @param[in] nCount iteration count
628 @retval rtl_Digest_E_None upon success.
630 SAL_DLLPUBLIC rtlDigestError SAL_CALL
rtl_digest_PBKDF2 (
631 sal_uInt8
*pKeyData
, sal_uInt32 nKeyLen
,
632 const sal_uInt8
*pPassData
, sal_uInt32 nPassLen
,
633 const sal_uInt8
*pSaltData
, sal_uInt32 nSaltLen
,
635 ) SAL_THROW_EXTERN_C();
641 #endif // INCLUDED_RTL_DIGEST_H
643 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */