tizen 2.3.1 release
[framework/security/secure-storage.git] / src / server / prng / include / ss_prng.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 //
15 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
16 //
17 // Licensed under the Apache License, Version 2.0 (the License);
18 // you may not use this file except in compliance with the License.
19 // You may obtain a copy of the License at
20 //
21 //     http://www.apache.org/licenses/LICENSE-2.0
22 //
23 // Unless required by applicable law or agreed to in writing, software
24 // distributed under the License is distributed on an "AS IS" BASIS,
25 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 // See the License for the specific language governing permissions and
27 // limitations under the License.
28 //
29
30 /**
31  *      @file   ss_prng.h
32  *      @brief  This header file contains declarations of Pseudo Random Function based on ANSI X9.31 Appendix A.2.4.
33  */
34
35 /**
36  *  Generate random numbers as per X9.31 specification using algorithm passed as input.
37  */
38
39 #ifndef __SS_PRNG__
40 #define __SS_PRNG__
41
42 #include "secure_storage.h"
43
44 struct evp_cipher_st;
45
46
47 #define SS_PRNG_SUCCESS 0
48 #define SS_PRNG_ERROR_INVALID_ARG -1
49 #define SS_PRNG_ERROR_OUT_OF_MEMORY -2
50 #define SS_PRNG_ERROR_SYSTEM -3
51
52
53 #define TryCatch(condition, expr, ...) \
54                 if (!(condition)) { \
55                         SLOGE(__VA_ARGS__); \
56                         expr; \
57                         goto CATCH; \
58                 } \
59                 else {;}
60
61 /**
62  * Generate random numbers as per X9.31 specification using algorithm passed as input.
63  *
64  * @return              Returns pointer to byte buffer containing generated random number.
65  * @param[in]   pAlg    Pointer to algorithm used for random number generation. Supports EVP_des_ecb(), EVP_des_ede3_ecb() and EVP_AES_128_ecb().
66  * @param[in]   requiredLength  Integer type indicating required size of random number.
67  */
68 unsigned char* GetRandomBytesN(struct evp_cipher_st* pAlg, long requiredLength);
69
70 #endif