Remove CTR bits param.
[platform/core/security/yaca.git] / src / internal.h
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file encrypt.h
21  * @brief Internal API
22  */
23
24 #ifndef YACA_INTERNAL_H
25 #define YACA_INTERNAL_H
26
27 #include <stddef.h>
28 #include <openssl/ossl_typ.h>
29
30 #include <yaca/types.h>
31
32 #define API __attribute__ ((visibility ("default")))
33
34 enum yaca_ctx_type_e
35 {
36         YACA_CTX_INVALID = 0,
37         YACA_CTX_DIGEST,
38         YACA_CTX_SIGN,
39         YACA_CTX_ENCRYPT,
40         YACA_CTX_SEAL
41 };
42
43 /* Base structure for crypto contexts - to be inherited */
44 struct yaca_ctx_s
45 {
46         enum yaca_ctx_type_e type;
47
48         void (*ctx_destroy)(const yaca_ctx_h ctx);
49         int (*get_output_length)(const yaca_ctx_h ctx, size_t input_len, size_t *output_len);
50         int (*set_param)(yaca_ctx_h ctx, yaca_ex_param_e param,
51                          const void *value, size_t value_len);
52         int (*get_param)(const yaca_ctx_h ctx, yaca_ex_param_e param,
53                          void **value, size_t *value_len);
54 };
55
56
57 /* Base structure for crypto keys - to be inherited */
58 struct yaca_key_s
59 {
60         yaca_key_type_e type;
61 };
62
63 /**
64  * Internal type for:
65  * - YACA_KEY_TYPE_SYMMETRIC
66  * - YACA_KEY_TYPE_DES
67  * - YACA_KEY_TYPE_IV
68  */
69 struct yaca_key_simple_s
70 {
71         struct yaca_key_s key;
72
73         size_t bits;
74         char d[];
75 };
76
77 /**
78  * Internal type for:
79  * - YACA_KEY_TYPE_RSA_PUB
80  * - YACA_KEY_TYPE_RSA_PRIV
81  * - YACA_KEY_TYPE_DSA_PUB
82  * - YACA_KEY_TYPE_DSA_PRIV
83  *
84  * TODO: and possibly others (for every key that uses EVP_PKEY)
85  */
86 struct yaca_key_evp_s
87 {
88         struct yaca_key_s key;
89
90         EVP_PKEY *evp;
91 };
92
93 int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md);
94
95 int encrypt_get_algorithm(yaca_enc_algo_e algo,
96                           yaca_block_cipher_mode_e bcm,
97                           size_t key_bits,
98                           const EVP_CIPHER **cipher);
99
100 struct yaca_key_simple_s *key_get_simple(const yaca_key_h key);
101 struct yaca_key_evp_s *key_get_evp(const yaca_key_h key);
102
103 void error_dump(const char *file, int line, const char *function, int code);
104 #define ERROR_DUMP(code) error_dump(__FILE__, __LINE__, __func__, (code))
105
106 #endif /* YACA_INTERNAL_H */