xref: /aoo41x/main/sal/inc/rtl/cipher.h (revision 514f4c20)
1*514f4c20SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*514f4c20SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*514f4c20SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*514f4c20SAndrew Rist  * distributed with this work for additional information
6*514f4c20SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*514f4c20SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*514f4c20SAndrew Rist  * "License"); you may not use this file except in compliance
9*514f4c20SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*514f4c20SAndrew Rist  *
11*514f4c20SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*514f4c20SAndrew Rist  *
13*514f4c20SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*514f4c20SAndrew Rist  * software distributed under the License is distributed on an
15*514f4c20SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*514f4c20SAndrew Rist  * KIND, either express or implied.  See the License for the
17*514f4c20SAndrew Rist  * specific language governing permissions and limitations
18*514f4c20SAndrew Rist  * under the License.
19*514f4c20SAndrew Rist  *
20*514f4c20SAndrew Rist  *************************************************************/
21*514f4c20SAndrew Rist 
22*514f4c20SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _RTL_CIPHER_H_
25cdf0e10cSrcweir #define _RTL_CIPHER_H_ "$Revision: 1.7 $"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sal/types.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifdef __cplusplus
30cdf0e10cSrcweir extern "C" {
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /*========================================================================
34cdf0e10cSrcweir  *
35cdf0e10cSrcweir  * rtlCipher interface.
36cdf0e10cSrcweir  *
37cdf0e10cSrcweir  *======================================================================*/
38cdf0e10cSrcweir /** Cipher Handle opaque type.
39cdf0e10cSrcweir  */
40cdf0e10cSrcweir typedef void* rtlCipher;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir /** Cipher Algorithm enumeration.
44cdf0e10cSrcweir 	@see rtl_cipher_create()
45cdf0e10cSrcweir  */
46cdf0e10cSrcweir enum __rtl_CipherAlgorithm
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	rtl_Cipher_AlgorithmBF,
49cdf0e10cSrcweir 	rtl_Cipher_AlgorithmARCFOUR,
50cdf0e10cSrcweir 	rtl_Cipher_AlgorithmInvalid,
51cdf0e10cSrcweir 	rtl_Cipher_Algorithm_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
52cdf0e10cSrcweir };
53cdf0e10cSrcweir 
54cdf0e10cSrcweir /** Cipher Algorithm type.
55cdf0e10cSrcweir  */
56cdf0e10cSrcweir typedef enum __rtl_CipherAlgorithm rtlCipherAlgorithm;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /** Cipher Mode enumeration.
60cdf0e10cSrcweir 	@see rtl_cipher_create()
61cdf0e10cSrcweir  */
62cdf0e10cSrcweir enum __rtl_CipherMode
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	rtl_Cipher_ModeECB,
65cdf0e10cSrcweir 	rtl_Cipher_ModeCBC,
66cdf0e10cSrcweir 	rtl_Cipher_ModeStream,
67cdf0e10cSrcweir 	rtl_Cipher_ModeInvalid,
68cdf0e10cSrcweir 	rtl_Cipher_Mode_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
69cdf0e10cSrcweir };
70cdf0e10cSrcweir 
71cdf0e10cSrcweir /** Cipher Mode type.
72cdf0e10cSrcweir  */
73cdf0e10cSrcweir typedef enum __rtl_CipherMode rtlCipherMode;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir /** Cipher Direction enumeration.
77cdf0e10cSrcweir 	@see rtl_cipher_init()
78cdf0e10cSrcweir  */
79cdf0e10cSrcweir enum __rtl_CipherDirection
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	rtl_Cipher_DirectionBoth,
82cdf0e10cSrcweir 	rtl_Cipher_DirectionDecode,
83cdf0e10cSrcweir 	rtl_Cipher_DirectionEncode,
84cdf0e10cSrcweir 	rtl_Cipher_DirectionInvalid,
85cdf0e10cSrcweir 	rtl_Cipher_Direction_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
86cdf0e10cSrcweir };
87cdf0e10cSrcweir 
88cdf0e10cSrcweir /** Cipher Direction type.
89cdf0e10cSrcweir  */
90cdf0e10cSrcweir typedef enum __rtl_CipherDirection rtlCipherDirection;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir /** Error Code enumeration.
94cdf0e10cSrcweir  */
95cdf0e10cSrcweir enum __rtl_CipherError
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	rtl_Cipher_E_None,
98cdf0e10cSrcweir 	rtl_Cipher_E_Argument,
99cdf0e10cSrcweir 	rtl_Cipher_E_Algorithm,
100cdf0e10cSrcweir 	rtl_Cipher_E_Direction,
101cdf0e10cSrcweir 	rtl_Cipher_E_Mode,
102cdf0e10cSrcweir 	rtl_Cipher_E_BufferSize,
103cdf0e10cSrcweir 	rtl_Cipher_E_Memory,
104cdf0e10cSrcweir 	rtl_Cipher_E_Unknown,
105cdf0e10cSrcweir 	rtl_Cipher_E_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
106cdf0e10cSrcweir };
107cdf0e10cSrcweir 
108cdf0e10cSrcweir /** Error Code type.
109cdf0e10cSrcweir  */
110cdf0e10cSrcweir typedef enum __rtl_CipherError rtlCipherError;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir /** Create a cipher handle for the given algorithm and mode.
114cdf0e10cSrcweir     @see rtlCipherAlgorithm
115cdf0e10cSrcweir     @see rtlCipherMode
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	@param  Algorithm [in] cipher algorithm.
118cdf0e10cSrcweir 	@param  Mode      [in] cipher mode.
119cdf0e10cSrcweir 	@return Cipher handle, or 0 upon failure.
120cdf0e10cSrcweir  */
121cdf0e10cSrcweir rtlCipher SAL_CALL rtl_cipher_create (
122cdf0e10cSrcweir 	rtlCipherAlgorithm Algorithm,
123cdf0e10cSrcweir 	rtlCipherMode      Mode
124cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir /** Inititialize a cipher for the given direction.
128cdf0e10cSrcweir     @see rtlCipherDirection
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	@param  Cipher    [in] cipher handle.
131cdf0e10cSrcweir 	@param  Direction [in] cipher direction.
132cdf0e10cSrcweir 	@param  pKeyData  [in] key material buffer.
133cdf0e10cSrcweir 	@param  nKeyLen   [in] key material length in bytes.
134cdf0e10cSrcweir 	@param  pArgData  [in] initialization vector buffer.
135cdf0e10cSrcweir 	@param  nArgLen   [in] initialization vector length in bytes.
136cdf0e10cSrcweir 	@return rtl_Cipher_E_None upon success.
137cdf0e10cSrcweir  */
138cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_init (
139cdf0e10cSrcweir 	rtlCipher           Cipher,
140cdf0e10cSrcweir 	rtlCipherDirection  Direction,
141cdf0e10cSrcweir 	const sal_uInt8    *pKeyData, sal_Size nKeyLen,
142cdf0e10cSrcweir 	const sal_uInt8    *pArgData, sal_Size nArgLen
143cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir /** Encode a buffer under a given cipher algorithm.
147cdf0e10cSrcweir     @precond Initialized for a compatible cipher direction.
148cdf0e10cSrcweir 	@see     rtl_cipher_init()
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	@param  Cipher  [in]  cipher handle.
151cdf0e10cSrcweir 	@param  pData   [in]  plaintext buffer.
152cdf0e10cSrcweir 	@param  nDatLen [in]  plaintext length in bytes.
153cdf0e10cSrcweir 	@param  pBuffer [out] ciphertext buffer.
154cdf0e10cSrcweir 	@param  nBufLen [in]  ciphertext length in bytes.
155cdf0e10cSrcweir 	@return rtl_Cipher_E_None upon success.
156cdf0e10cSrcweir  */
157cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_encode (
158cdf0e10cSrcweir 	rtlCipher   Cipher,
159cdf0e10cSrcweir 	const void *pData,   sal_Size nDatLen,
160cdf0e10cSrcweir 	sal_uInt8  *pBuffer, sal_Size nBufLen
161cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir /** Decode a buffer under a given cipher algorithm.
165cdf0e10cSrcweir     @precond Initialized for a compatible cipher direction.
166cdf0e10cSrcweir 	@see     rtl_cipher_init()
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	@param  Cipher  [in]  cipher handle.
169cdf0e10cSrcweir 	@param  pData   [in]  ciphertext buffer.
170cdf0e10cSrcweir 	@param  nDatLen [in]  ciphertext length in bytes.
171cdf0e10cSrcweir 	@param  pBuffer [out] plaintext buffer.
172cdf0e10cSrcweir 	@param  nBufLen [in]  plaintext length in bytes.
173cdf0e10cSrcweir 	@return rtl_Cipher_E_None upon success.
174cdf0e10cSrcweir  */
175cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_decode (
176cdf0e10cSrcweir 	rtlCipher   Cipher,
177cdf0e10cSrcweir 	const void *pData,   sal_Size nDatLen,
178cdf0e10cSrcweir 	sal_uInt8  *pBuffer, sal_Size nBufLen
179cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 
182cdf0e10cSrcweir /** Destroy a cipher handle.
183cdf0e10cSrcweir 	@param  Cipher [in] cipher handle to be destroyed.
184cdf0e10cSrcweir 	@return None. Cipher handle destroyed and invalid.
185cdf0e10cSrcweir  */
186cdf0e10cSrcweir void SAL_CALL rtl_cipher_destroy (
187cdf0e10cSrcweir 	rtlCipher Cipher
188cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir /*========================================================================
192cdf0e10cSrcweir  *
193cdf0e10cSrcweir  * rtl_cipherBF (Blowfish) interface.
194cdf0e10cSrcweir  *
195cdf0e10cSrcweir  *======================================================================*/
196cdf0e10cSrcweir /** Create a Blowfish cipher handle for the given mode.
197cdf0e10cSrcweir     @descr The Blowfish block cipher algorithm is specified in
198cdf0e10cSrcweir 	Bruce Schneier: Applied Cryptography, 2nd edition, ch. 14.3
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	@see rtl_cipher_create()
201cdf0e10cSrcweir  */
202cdf0e10cSrcweir rtlCipher SAL_CALL rtl_cipher_createBF (
203cdf0e10cSrcweir 	rtlCipherMode Mode
204cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir /** Inititialize a Blowfish cipher for the given direction.
208cdf0e10cSrcweir 	@see rtl_cipher_init()
209cdf0e10cSrcweir  */
210cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_initBF (
211cdf0e10cSrcweir 	rtlCipher          Cipher,
212cdf0e10cSrcweir 	rtlCipherDirection Direction,
213cdf0e10cSrcweir 	const sal_uInt8 *pKeyData, sal_Size nKeyLen,
214cdf0e10cSrcweir 	const sal_uInt8 *pArgData, sal_Size nArgLen
215cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 
218cdf0e10cSrcweir /** Encode a buffer under the Blowfish cipher algorithm.
219cdf0e10cSrcweir 	@see rtl_cipher_encode()
220cdf0e10cSrcweir  */
221cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_encodeBF (
222cdf0e10cSrcweir 	rtlCipher   Cipher,
223cdf0e10cSrcweir 	const void *pData,   sal_Size nDatLen,
224cdf0e10cSrcweir 	sal_uInt8  *pBuffer, sal_Size nBufLen
225cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir /** Decode a buffer under the Blowfish cipher algorithm.
229cdf0e10cSrcweir 	@see rtl_cipher_decode()
230cdf0e10cSrcweir  */
231cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_decodeBF (
232cdf0e10cSrcweir 	rtlCipher   Cipher,
233cdf0e10cSrcweir 	const void *pData,   sal_Size nDatLen,
234cdf0e10cSrcweir 	sal_uInt8  *pBuffer, sal_Size nBufLen
235cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 
238cdf0e10cSrcweir /** Destroy a Blowfish cipher handle.
239cdf0e10cSrcweir 	@see rtl_cipher_destroy()
240cdf0e10cSrcweir  */
241cdf0e10cSrcweir void SAL_CALL rtl_cipher_destroyBF (
242cdf0e10cSrcweir 	rtlCipher Cipher
243cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 
246cdf0e10cSrcweir /*========================================================================
247cdf0e10cSrcweir  *
248cdf0e10cSrcweir  * rtl_cipherARCFOUR (RC4) interface.
249cdf0e10cSrcweir  *
250cdf0e10cSrcweir  *======================================================================*/
251cdf0e10cSrcweir /** Create a RC4 cipher handle for the given mode.
252cdf0e10cSrcweir     @descr The RC4 symmetric stream cipher algorithm is specified in
253cdf0e10cSrcweir 	Bruce Schneier: Applied Cryptography, 2nd edition, ch. 17.1
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	@see rtl_cipher_create()
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	@param  Mode [in] cipher mode. Must be rtl_Cipher_ModeStream.
258cdf0e10cSrcweir 	@return Cipher handle, or 0 upon failure.
259cdf0e10cSrcweir  */
260cdf0e10cSrcweir rtlCipher SAL_CALL rtl_cipher_createARCFOUR (
261cdf0e10cSrcweir 	rtlCipherMode Mode
262cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 
265cdf0e10cSrcweir /** Inititialize a RC4 cipher for the given direction.
266cdf0e10cSrcweir 	@see rtl_cipher_init()
267cdf0e10cSrcweir  */
268cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_initARCFOUR (
269cdf0e10cSrcweir 	rtlCipher          Cipher,
270cdf0e10cSrcweir 	rtlCipherDirection Direction,
271cdf0e10cSrcweir 	const sal_uInt8 *pKeyData, sal_Size nKeyLen,
272cdf0e10cSrcweir 	const sal_uInt8 *pArgData, sal_Size nArgLen
273cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
276cdf0e10cSrcweir /** Encode a buffer under the RC4 cipher algorithm.
277cdf0e10cSrcweir 	@see rtl_cipher_encode()
278cdf0e10cSrcweir  */
279cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_encodeARCFOUR (
280cdf0e10cSrcweir 	rtlCipher   Cipher,
281cdf0e10cSrcweir 	const void *pData,   sal_Size nDatLen,
282cdf0e10cSrcweir 	sal_uInt8  *pBuffer, sal_Size nBufLen
283cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 
286cdf0e10cSrcweir /** Decode a buffer under the RC4 cipher algorithm.
287cdf0e10cSrcweir 	@see rtl_cipher_decode()
288cdf0e10cSrcweir  */
289cdf0e10cSrcweir rtlCipherError SAL_CALL rtl_cipher_decodeARCFOUR (
290cdf0e10cSrcweir 	rtlCipher   Cipher,
291cdf0e10cSrcweir 	const void *pData,   sal_Size nDatLen,
292cdf0e10cSrcweir 	sal_uInt8  *pBuffer, sal_Size nBufLen
293cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 
296cdf0e10cSrcweir /** Destroy a RC4 cipher handle.
297cdf0e10cSrcweir 	@see rtl_cipher_destroy()
298cdf0e10cSrcweir  */
299cdf0e10cSrcweir void SAL_CALL rtl_cipher_destroyARCFOUR (
300cdf0e10cSrcweir 	rtlCipher Cipher
301cdf0e10cSrcweir ) SAL_THROW_EXTERN_C();
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 
304cdf0e10cSrcweir /*========================================================================
305cdf0e10cSrcweir  *
306cdf0e10cSrcweir  * The End.
307cdf0e10cSrcweir  *
308cdf0e10cSrcweir  *======================================================================*/
309cdf0e10cSrcweir 
310cdf0e10cSrcweir #ifdef __cplusplus
311cdf0e10cSrcweir }
312cdf0e10cSrcweir #endif
313cdf0e10cSrcweir 
314cdf0e10cSrcweir #endif /* !_RTL_CIPHER_H_ */
315cdf0e10cSrcweir 
316