memcpy(seed + 13, s->hiskex + 1, 32);
memcpy(seed + 45, s->mykex + 1, 32);
}
- memcpy(seed + 78, s->label, s->labellen);
+ memcpy(seed + 77, s->label, s->labellen);
// Use PRF to generate the key material
if(!prf(shared, len, seed, s->labellen + 64 + 13, s->key, keylen))
// Receive a handshake record.
static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) {
// Only a few states to deal with handshaking.
- fprintf(stderr, "Received handshake message, current state %d\n", s->state);
switch(s->state) {
case SPTPS_SECONDARY_KEX:
// We receive a secondary KEX request, first respond by sending our own.
} else if (seqno < s->inseqno) {
// If the sequence number is farther in the past than the bitmap goes, or if the packet was already received, drop it.
if((s->inseqno >= s->replaywin * 8 && seqno < s->inseqno - s->replaywin * 8) || !(s->late[(seqno / 8) % s->replaywin] & (1 << seqno % 8))) {
- fprintf(stderr, "Received late or replayed packet, seqno %d, last received %d", seqno, s->inseqno);
+ fprintf(stderr, "Received late or replayed packet, seqno %d, last received %d\n", seqno, s->inseqno);
return false;
}
} else {
s->buflen += toread;
len -= toread;
data += toread;
-
+
// Exit early if we don't have the full length.
if(s->buflen < 6)
return true;
// Stop a SPTPS session.
bool sptps_stop(sptps_t *s) {
// Clean up any resources.
+ cipher_close(&s->incipher);
+ cipher_close(&s->outcipher);
+ digest_close(&s->indigest);
+ digest_close(&s->outdigest);
ecdh_free(&s->ecdh);
free(s->inbuf);
- s->inbuf = NULL;
free(s->mykex);
- s->mykex = NULL;
free(s->hiskex);
- s->hiskex = NULL;
free(s->key);
- s->key = NULL;
free(s->label);
- s->label = NULL;
free(s->late);
- s->late = NULL;
+ memset(s, 0, sizeof *s);
return true;
}