{
VERBOSE (crypto, TRACE, PRINTF ("load_key_func\n"));
+ //FIXIT: not thread safe
+ state_t old_state = state;
+ state = updating_e;
+
int kid = in->key_id;
int klen = in->key_len;
free (keys[kid]);
channels[kid] = kid + 1;
VERBOSE(crypto, DEBUG, PRINTF ("load key (%d) stored in channels (%d)\n", kid, channels[kid]));
#endif
+ state = old_state;
out->status = ok_e;
{
VERBOSE (crypto, TRACE, PRINTF ("unload_key_func\n"));
+ //FIXIT: not thread safe
+#ifdef PROTOCOL_EXT
+ state_t old_state = state;
+#endif
+ state = updating_e;
+
int kid = in->key_id;
#ifdef PROTOCOL_EXT
for (int i = 0; i < NB_CHANNELS; i++) {
if (channels[i] == kid + 1) {
VERBOSE (crypto, WARNING, PRINTF ("key (%d) is still associated to a channel (%d)\n", kid, i));
out->status = error_e;
+ state = old_state;
return 0;
}
}
#ifndef PROTOCOL_EXT
channels[kid] = 0;
+
+ state = ready_e;
+#else
+ state_t _state = initializing_e;
+ for (int i = 0; i < NB_CHANNELS; i++) {
+ if (channels[i]) {
+ _state = ready_e;
+ break;
+ }
+ }
+ state = _state;
#endif
return 0;
{
VERBOSE (crypto, TRACE, PRINTF ("erase_key_func\n"));
+ //FIXIT: not thread safe
+#ifdef PROTOCOL_EXT
+ state_t old_state = state;
+#endif
+ state = updating_e;
+
if (in->key_id != 255) {
VERBOSE (crypto, WARNING, PRINTF ("incorrect ERRASE_KEY message\n"));
}
for (int i = 0; i < NB_CHANNELS; i++) {
if (channels[i]) {
VERBOSE (crypto, WARNING, PRINTF ("key (%d) is still associated to a channel (%d)\n", channels[i] - 1, i));
+ state = old_state;
out->status = error_e;
return 0;
}
memset (keys, 0, NB_KEYS * sizeof (uint8_t *));
memset (key_lengths, 0, NB_KEYS * sizeof (int));
+#ifndef PROTOCOL_EXT
+ state = ready_e;
+#else
+ state = initializing_e;
+#endif
+
out->status = ok_e;
return 0;
{
VERBOSE (crypto, TRACE, PRINTF ("associate_channel_func\n"));
+ //FIXIT: not thread safe
+#ifdef PROTOCOL_EXT
+ state_t old_state = state;
+#endif
+ state = updating_e;
+
int cid = in->channel_id;
int kid = in->key_id;
#ifdef PROTOCOL_EXT
if (keys[kid] == NULL) {
VERBOSE (crypto, WARNING, PRINTF ("can't associate channnel id to empty key (%d)\n", kid));
+ state = old_state;
out->status = error_e;
} else {
channels[cid] = kid + 1;
- if (state == initializing_e) {
- state = ready_e;
- }
+ state = ready_e;
out->status = ok_e;
}
#else
channels[cid] = kid + 1;
+ state = ready_e;
out->status = ok_e;
#endif
{
VERBOSE (crypto, TRACE, PRINTF ("dissociate_channel_func\n"));
+ //FIXIT: not thread safe
+#ifdef PROTOCOL_EXT
+ state_t old_state = state;
+#endif
+ state = updating_e;
+
int cid = in->channel_id;
#ifdef PROTOCOL_EXT
if (channels[cid] == 0) {
VERBOSE (crypto, WARNING, PRINTF ("no key associated to channnel id (%d)\n", cid));
+ state = old_state;
out->status = error_e;
} else if (keys[channels[cid] - 1] == NULL) {
VERBOSE (crypto, WARNING, PRINTF ("can't dissociate channnel id to empty key (%d)\n", cid));
+ state = old_state;
out->status = error_e;
} else {
channels[cid] = 0;
_state = ready_e;
}
}
- if (_state == initializing_e) {
- // FIXIT: not thread safe
- state = initializing_e;
- }
+ state = _state;
out->status = ok_e;
}
#else
VERBOSE (crypto, WARNING, PRINTF ("no key associated to channnel id (%d)\n", cid));
out->status = error_e;
}
+ state = ready_e;
#endif
return 0;
out->data_len = strlen (correct_answer);
memcpy (out->data, correct_answer, out->data_len);
state = initializing_e;
+ //state = error_e;
} else {
out->data_len = strlen (wrong_answer);
memcpy (out->data, wrong_answer, out->data_len);
{
VERBOSE (crypto, TRACE, PRINTF ("zeroize_func\n"));
+ // FIXIT: not thread safe
+ state = updating_e;
+
clean_crypto_memory ();
- // FIXIT: not thread safe
+#ifdef PROTOCOL_EXT
+ state = initializing_e;
+#else
state = ready_e;
+#endif
out->status = ok_e;
memset (keys, 0, NB_KEYS * sizeof (uint8_t *));
memset (key_lengths, 0, NB_KEYS * sizeof (int));
memset (channels, 0, NB_CHANNELS * sizeof (uint8_t));
- state = ready_e;
}
/* vim: set ts=4 sw=4 si et: */