diff options
Diffstat (limited to 'src/lib/libcrypto/engine/tb_cipher.c')
-rw-r--r-- | src/lib/libcrypto/engine/tb_cipher.c | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c index 8d45a9a9cf..3218f5d86f 100644 --- a/src/lib/libcrypto/engine/tb_cipher.c +++ b/src/lib/libcrypto/engine/tb_cipher.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * are met: | 6 | * are met: |
7 | * | 7 | * |
8 | * 1. Redistributions of source code must retain the above copyright | 8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. | 9 | * notice, this list of conditions and the following disclaimer. |
10 | * | 10 | * |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in | 12 | * notice, this list of conditions and the following disclaimer in |
@@ -61,83 +61,90 @@ | |||
61 | 61 | ||
62 | static ENGINE_TABLE *cipher_table = NULL; | 62 | static ENGINE_TABLE *cipher_table = NULL; |
63 | 63 | ||
64 | void ENGINE_unregister_ciphers(ENGINE *e) | 64 | void |
65 | { | 65 | ENGINE_unregister_ciphers(ENGINE *e) |
66 | { | ||
66 | engine_table_unregister(&cipher_table, e); | 67 | engine_table_unregister(&cipher_table, e); |
67 | } | 68 | } |
68 | 69 | ||
69 | static void engine_unregister_all_ciphers(void) | 70 | static void |
70 | { | 71 | engine_unregister_all_ciphers(void) |
72 | { | ||
71 | engine_table_cleanup(&cipher_table); | 73 | engine_table_cleanup(&cipher_table); |
72 | } | 74 | } |
73 | 75 | ||
74 | int ENGINE_register_ciphers(ENGINE *e) | 76 | int |
75 | { | 77 | ENGINE_register_ciphers(ENGINE *e) |
76 | if(e->ciphers) | 78 | { |
77 | { | 79 | if (e->ciphers) { |
78 | const int *nids; | 80 | const int *nids; |
79 | int num_nids = e->ciphers(e, NULL, &nids, 0); | 81 | int num_nids = e->ciphers(e, NULL, &nids, 0); |
80 | if(num_nids > 0) | 82 | if (num_nids > 0) |
81 | return engine_table_register(&cipher_table, | 83 | return engine_table_register(&cipher_table, |
82 | engine_unregister_all_ciphers, e, nids, | 84 | engine_unregister_all_ciphers, e, nids, |
83 | num_nids, 0); | 85 | num_nids, 0); |
84 | } | ||
85 | return 1; | ||
86 | } | 86 | } |
87 | return 1; | ||
88 | } | ||
87 | 89 | ||
88 | void ENGINE_register_all_ciphers(void) | 90 | void |
89 | { | 91 | ENGINE_register_all_ciphers(void) |
92 | { | ||
90 | ENGINE *e; | 93 | ENGINE *e; |
91 | 94 | ||
92 | for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) | 95 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) |
93 | ENGINE_register_ciphers(e); | 96 | ENGINE_register_ciphers(e); |
94 | } | 97 | } |
95 | 98 | ||
96 | int ENGINE_set_default_ciphers(ENGINE *e) | 99 | int |
97 | { | 100 | ENGINE_set_default_ciphers(ENGINE *e) |
98 | if(e->ciphers) | 101 | { |
99 | { | 102 | if (e->ciphers) { |
100 | const int *nids; | 103 | const int *nids; |
101 | int num_nids = e->ciphers(e, NULL, &nids, 0); | 104 | int num_nids = e->ciphers(e, NULL, &nids, 0); |
102 | if(num_nids > 0) | 105 | if (num_nids > 0) |
103 | return engine_table_register(&cipher_table, | 106 | return engine_table_register(&cipher_table, |
104 | engine_unregister_all_ciphers, e, nids, | 107 | engine_unregister_all_ciphers, e, nids, |
105 | num_nids, 1); | 108 | num_nids, 1); |
106 | } | ||
107 | return 1; | ||
108 | } | 109 | } |
110 | return 1; | ||
111 | } | ||
109 | 112 | ||
110 | /* Exposed API function to get a functional reference from the implementation | 113 | /* Exposed API function to get a functional reference from the implementation |
111 | * table (ie. try to get a functional reference from the tabled structural | 114 | * table (ie. try to get a functional reference from the tabled structural |
112 | * references) for a given cipher 'nid' */ | 115 | * references) for a given cipher 'nid' */ |
113 | ENGINE *ENGINE_get_cipher_engine(int nid) | 116 | ENGINE * |
114 | { | 117 | ENGINE_get_cipher_engine(int nid) |
118 | { | ||
115 | return engine_table_select(&cipher_table, nid); | 119 | return engine_table_select(&cipher_table, nid); |
116 | } | 120 | } |
117 | 121 | ||
118 | /* Obtains a cipher implementation from an ENGINE functional reference */ | 122 | /* Obtains a cipher implementation from an ENGINE functional reference */ |
119 | const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid) | 123 | const EVP_CIPHER * |
120 | { | 124 | ENGINE_get_cipher(ENGINE *e, int nid) |
125 | { | ||
121 | const EVP_CIPHER *ret; | 126 | const EVP_CIPHER *ret; |
122 | ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e); | 127 | ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e); |
123 | if(!fn || !fn(e, &ret, NULL, nid)) | 128 | |
124 | { | 129 | if (!fn || !fn(e, &ret, NULL, nid)) { |
125 | ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER, | 130 | ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER, |
126 | ENGINE_R_UNIMPLEMENTED_CIPHER); | 131 | ENGINE_R_UNIMPLEMENTED_CIPHER); |
127 | return NULL; | 132 | return NULL; |
128 | } | ||
129 | return ret; | ||
130 | } | 133 | } |
134 | return ret; | ||
135 | } | ||
131 | 136 | ||
132 | /* Gets the cipher callback from an ENGINE structure */ | 137 | /* Gets the cipher callback from an ENGINE structure */ |
133 | ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e) | 138 | ENGINE_CIPHERS_PTR |
134 | { | 139 | ENGINE_get_ciphers(const ENGINE *e) |
140 | { | ||
135 | return e->ciphers; | 141 | return e->ciphers; |
136 | } | 142 | } |
137 | 143 | ||
138 | /* Sets the cipher callback in an ENGINE structure */ | 144 | /* Sets the cipher callback in an ENGINE structure */ |
139 | int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f) | 145 | int |
140 | { | 146 | ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f) |
147 | { | ||
141 | e->ciphers = f; | 148 | e->ciphers = f; |
142 | return 1; | 149 | return 1; |
143 | } | 150 | } |