1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cipher.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _RTL_CIPHER_H_
32 #define _RTL_CIPHER_H_ "$Revision: 1.7 $"
34 #include <sal/types.h>
40 /*========================================================================
42 * rtlCipher interface.
44 *======================================================================*/
45 /** Cipher Handle opaque type.
47 typedef void* rtlCipher
;
50 /** Cipher Algorithm enumeration.
51 @see rtl_cipher_create()
53 enum __rtl_CipherAlgorithm
55 rtl_Cipher_AlgorithmBF
,
56 rtl_Cipher_AlgorithmARCFOUR
,
57 rtl_Cipher_AlgorithmInvalid
,
58 rtl_Cipher_Algorithm_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
61 /** Cipher Algorithm type.
63 typedef enum __rtl_CipherAlgorithm rtlCipherAlgorithm
;
66 /** Cipher Mode enumeration.
67 @see rtl_cipher_create()
73 rtl_Cipher_ModeStream
,
74 rtl_Cipher_ModeInvalid
,
75 rtl_Cipher_Mode_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
80 typedef enum __rtl_CipherMode rtlCipherMode
;
83 /** Cipher Direction enumeration.
84 @see rtl_cipher_init()
86 enum __rtl_CipherDirection
88 rtl_Cipher_DirectionBoth
,
89 rtl_Cipher_DirectionDecode
,
90 rtl_Cipher_DirectionEncode
,
91 rtl_Cipher_DirectionInvalid
,
92 rtl_Cipher_Direction_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
95 /** Cipher Direction type.
97 typedef enum __rtl_CipherDirection rtlCipherDirection
;
100 /** Error Code enumeration.
102 enum __rtl_CipherError
105 rtl_Cipher_E_Argument
,
106 rtl_Cipher_E_Algorithm
,
107 rtl_Cipher_E_Direction
,
109 rtl_Cipher_E_BufferSize
,
111 rtl_Cipher_E_Unknown
,
112 rtl_Cipher_E_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
117 typedef enum __rtl_CipherError rtlCipherError
;
120 /** Create a cipher handle for the given algorithm and mode.
121 @see rtlCipherAlgorithm
124 @param Algorithm [in] cipher algorithm.
125 @param Mode [in] cipher mode.
126 @return Cipher handle, or 0 upon failure.
128 rtlCipher SAL_CALL
rtl_cipher_create (
129 rtlCipherAlgorithm Algorithm
,
131 ) SAL_THROW_EXTERN_C();
134 /** Inititialize a cipher for the given direction.
135 @see rtlCipherDirection
137 @param Cipher [in] cipher handle.
138 @param Direction [in] cipher direction.
139 @param pKeyData [in] key material buffer.
140 @param nKeyLen [in] key material length in bytes.
141 @param pArgData [in] initialization vector buffer.
142 @param nArgLen [in] initialization vector length in bytes.
143 @return rtl_Cipher_E_None upon success.
145 rtlCipherError SAL_CALL
rtl_cipher_init (
147 rtlCipherDirection Direction
,
148 const sal_uInt8
*pKeyData
, sal_Size nKeyLen
,
149 const sal_uInt8
*pArgData
, sal_Size nArgLen
150 ) SAL_THROW_EXTERN_C();
153 /** Encode a buffer under a given cipher algorithm.
154 @precond Initialized for a compatible cipher direction.
155 @see rtl_cipher_init()
157 @param Cipher [in] cipher handle.
158 @param pData [in] plaintext buffer.
159 @param nDatLen [in] plaintext length in bytes.
160 @param pBuffer [out] ciphertext buffer.
161 @param nBufLen [in] ciphertext length in bytes.
162 @return rtl_Cipher_E_None upon success.
164 rtlCipherError SAL_CALL
rtl_cipher_encode (
166 const void *pData
, sal_Size nDatLen
,
167 sal_uInt8
*pBuffer
, sal_Size nBufLen
168 ) SAL_THROW_EXTERN_C();
171 /** Decode a buffer under a given cipher algorithm.
172 @precond Initialized for a compatible cipher direction.
173 @see rtl_cipher_init()
175 @param Cipher [in] cipher handle.
176 @param pData [in] ciphertext buffer.
177 @param nDatLen [in] ciphertext length in bytes.
178 @param pBuffer [out] plaintext buffer.
179 @param nBufLen [in] plaintext length in bytes.
180 @return rtl_Cipher_E_None upon success.
182 rtlCipherError SAL_CALL
rtl_cipher_decode (
184 const void *pData
, sal_Size nDatLen
,
185 sal_uInt8
*pBuffer
, sal_Size nBufLen
186 ) SAL_THROW_EXTERN_C();
189 /** Destroy a cipher handle.
190 @param Cipher [in] cipher handle to be destroyed.
191 @return None. Cipher handle destroyed and invalid.
193 void SAL_CALL
rtl_cipher_destroy (
195 ) SAL_THROW_EXTERN_C();
198 /*========================================================================
200 * rtl_cipherBF (Blowfish) interface.
202 *======================================================================*/
203 /** Create a Blowfish cipher handle for the given mode.
204 @descr The Blowfish block cipher algorithm is specified in
205 Bruce Schneier: Applied Cryptography, 2nd edition, ch. 14.3
207 @see rtl_cipher_create()
209 rtlCipher SAL_CALL
rtl_cipher_createBF (
211 ) SAL_THROW_EXTERN_C();
214 /** Inititialize a Blowfish cipher for the given direction.
215 @see rtl_cipher_init()
217 rtlCipherError SAL_CALL
rtl_cipher_initBF (
219 rtlCipherDirection Direction
,
220 const sal_uInt8
*pKeyData
, sal_Size nKeyLen
,
221 const sal_uInt8
*pArgData
, sal_Size nArgLen
222 ) SAL_THROW_EXTERN_C();
225 /** Encode a buffer under the Blowfish cipher algorithm.
226 @see rtl_cipher_encode()
228 rtlCipherError SAL_CALL
rtl_cipher_encodeBF (
230 const void *pData
, sal_Size nDatLen
,
231 sal_uInt8
*pBuffer
, sal_Size nBufLen
232 ) SAL_THROW_EXTERN_C();
235 /** Decode a buffer under the Blowfish cipher algorithm.
236 @see rtl_cipher_decode()
238 rtlCipherError SAL_CALL
rtl_cipher_decodeBF (
240 const void *pData
, sal_Size nDatLen
,
241 sal_uInt8
*pBuffer
, sal_Size nBufLen
242 ) SAL_THROW_EXTERN_C();
245 /** Destroy a Blowfish cipher handle.
246 @see rtl_cipher_destroy()
248 void SAL_CALL
rtl_cipher_destroyBF (
250 ) SAL_THROW_EXTERN_C();
253 /*========================================================================
255 * rtl_cipherARCFOUR (RC4) interface.
257 *======================================================================*/
258 /** Create a RC4 cipher handle for the given mode.
259 @descr The RC4 symmetric stream cipher algorithm is specified in
260 Bruce Schneier: Applied Cryptography, 2nd edition, ch. 17.1
262 @see rtl_cipher_create()
264 @param Mode [in] cipher mode. Must be rtl_Cipher_ModeStream.
265 @return Cipher handle, or 0 upon failure.
267 rtlCipher SAL_CALL
rtl_cipher_createARCFOUR (
269 ) SAL_THROW_EXTERN_C();
272 /** Inititialize a RC4 cipher for the given direction.
273 @see rtl_cipher_init()
275 rtlCipherError SAL_CALL
rtl_cipher_initARCFOUR (
277 rtlCipherDirection Direction
,
278 const sal_uInt8
*pKeyData
, sal_Size nKeyLen
,
279 const sal_uInt8
*pArgData
, sal_Size nArgLen
280 ) SAL_THROW_EXTERN_C();
283 /** Encode a buffer under the RC4 cipher algorithm.
284 @see rtl_cipher_encode()
286 rtlCipherError SAL_CALL
rtl_cipher_encodeARCFOUR (
288 const void *pData
, sal_Size nDatLen
,
289 sal_uInt8
*pBuffer
, sal_Size nBufLen
290 ) SAL_THROW_EXTERN_C();
293 /** Decode a buffer under the RC4 cipher algorithm.
294 @see rtl_cipher_decode()
296 rtlCipherError SAL_CALL
rtl_cipher_decodeARCFOUR (
298 const void *pData
, sal_Size nDatLen
,
299 sal_uInt8
*pBuffer
, sal_Size nBufLen
300 ) SAL_THROW_EXTERN_C();
303 /** Destroy a RC4 cipher handle.
304 @see rtl_cipher_destroy()
306 void SAL_CALL
rtl_cipher_destroyARCFOUR (
308 ) SAL_THROW_EXTERN_C();
311 /*========================================================================
315 *======================================================================*/
321 #endif /* !_RTL_CIPHER_H_ */