38
38
* Allocates and initializes an Alpha C association with default values
39
39
* and creates necessary default structures.
41
41
* @param[in] id the identifier of this association (should be unique as this is the position in the relay array)
43
43
* @return the new association
45
45
struct association_relay *association_relay_new_alpha_c_ass(const unsigned int id) {
46
struct association_relay *ass = xmalloc(sizeof(struct association_relay));
50
ap_presig_store_init(&ass->alpha_c.pstore);
46
struct association_relay *ass = xmalloc(sizeof(struct association_relay));
50
ap_presig_store_init(&ass->alpha_c.pstore);
55
55
//! Frees a given ALpha C Association
57
* The association is freed if a not null pointer is passed.
58
* If the pointer is a null pointer no operation is performed.
57
* The association is freed if a not null pointer is passed.
58
* If the pointer is a null pointer no operation is performed.
60
60
* @note This function should be called by association_relay_free() only
61
61
* @param[in] ass the association to be freed
63
63
void association_relay_free_alpha_c_ass(struct association_relay *ass) {
65
print_error("can't free NULL association_relay");
69
assert(ass->mode == ALPHA_C);
65
print_error("can't free NULL association_relay");
69
assert(ass->mode == ALPHA_C);
74
74
//! Handles an incoming Alpha C packet
76
* Handles a given S1 packet. Hash chain checks are performed in
77
* association_relay_handle_s1(). This function handles only the
76
* Handles a given S1 packet. Hash chain checks are performed in
77
* association_relay_handle_s1(). This function handles only the
78
78
* special functions for Alpha C, i.e. buffering received HMACs.
80
80
* @param[in,out] ass The association on that the packet came in
81
81
* @param[in] packet the incoming packet
82
82
* @param[in] packet_len the size of the packet (including the header)
84
84
void association_relay_handle_s1_alpha_c(struct association_relay *const ass, struct alpha_packet const *const packet, unsigned int const packet_len) {
86
assert(ass->mode == ALPHA_C);
87
assert(packet != NULL);
88
assert(packet->type == PACKET_S1);
89
assert(packet_len > 0);
90
const unsigned int sig_count = ntohs(packet->s1.signatures_count);
92
rel_stats.s1_packets_alpha_C++;
94
if(packet_len != packet_size(s1.common) + sig_count * sizeof(digest_t)) {
95
AP_MSG_F(AP_MSG_LVL_ERROR, AP_MSG_CTX,"Actual packet size does not match size computed from signature count: %d != %d\n",
97
packet_size(s1.common) + sig_count * sizeof(digest_t));
101
// Keep statistics of how many pre-signatures were wasted
102
rel_stats.s1_wasted_presigs_alpha_C += (MAX_PRESIG_COUNT - sig_count);
105
ap_presig_store_put(&ass->alpha_c.pstore, &packet->s1.anchor, packet->s1.common.presigs, sig_count);
107
ass->alpha_c.packets_to_receive = sig_count;
108
ass->alpha_c.packets_received = 0;
86
assert(ass->mode == ALPHA_C);
87
assert(packet != NULL);
88
assert(packet->type == PACKET_S1);
89
assert(packet_len > 0);
90
const unsigned int sig_count = ntohs(packet->s1.signatures_count);
92
rel_stats.s1_packets_alpha_C++;
94
if (packet_len != packet_size(s1.common) + sig_count * sizeof(digest_t)) {
95
AP_MSG_F(AP_MSG_LVL_ERROR, AP_MSG_CTX, "Actual packet size does not match size computed from signature count: %d != %d\n",
97
packet_size(s1.common) + sig_count * sizeof(digest_t));
101
// Keep statistics of how many pre-signatures were wasted
102
rel_stats.s1_wasted_presigs_alpha_C += (MAX_PRESIG_COUNT - sig_count);
105
ap_presig_store_put(&ass->alpha_c.pstore, &packet->s1.anchor, packet->s1.common.presigs, sig_count);
107
ass->alpha_c.packets_to_receive = sig_count;
108
ass->alpha_c.packets_received = 0;
112
111
//! Verifies a given Alpha S2 packet
114
113
* Verifies a given Alpha S2 packet with the content of the buffer in the given Alpha C association.
116
115
* @param[in] ass the association on that the packet came in
117
116
* @param[in] packet the incoming packet
118
117
* @param[in] packet_len the size of the incoming packet (including the header)
119
118
* @param[out] valid if the packet is valid (checked with the given HMAC)
121
120
void association_relay_verify_alpha_c(struct association_relay *const ass, struct alpha_packet const *const packet, unsigned int const packet_len, bool *const valid) {
123
assert(ass->mode == ALPHA_C);
124
assert(packet != NULL);
125
assert(packet->type == PACKET_S2);
128
digest_t computed_hmac;
129
digest_t computed_anchor;
131
const int payload_len = packet_len - packet_size(s2.common);
133
create_digest(&packet->s2.common.anchor, sizeof(digest_t), &computed_anchor);
134
create_hmac(packet->s2.common.payload, payload_len, &packet->s2.common.anchor, &computed_hmac);
137
*valid = ap_presig_check_store(&ass->alpha_c.pstore,
140
ntohs(packet->s2.common.data_index));
143
ass->alpha_c.packets_received++;
122
assert(ass->mode == ALPHA_C);
123
assert(packet != NULL);
124
assert(packet->type == PACKET_S2);
127
digest_t computed_hmac;
128
digest_t computed_anchor;
130
const int payload_len = packet_len - packet_size(s2.common);
132
create_digest(&packet->s2.common.anchor, sizeof(digest_t), &computed_anchor);
133
create_hmac(packet->s2.common.payload, payload_len, &packet->s2.common.anchor, &computed_hmac);
136
*valid = ap_presig_check_store(&ass->alpha_c.pstore,
139
ntohs(packet->s2.common.data_index));
142
ass->alpha_c.packets_received++;