1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00
putty-source/crypto/mac.c
Simon Tatham 5b30e6f7a6 Move crypto into its own subdirectory.
Similarly to 'utils', I've moved all the stuff in the crypto
build-time library into a source directory of its own, and while I'm
at it, split up the monolithic sshauxcrypt.c into its various
unrelated parts.

This is also an opportunity to remove the annoying 'ssh' prefix from
the front of the file names, and give several of them less cryptic
names.
2021-04-21 21:55:26 +01:00

44 lines
1.1 KiB
C

/*
* Centralised parts of the SSH-2 MAC API, which don't need to vary
* with the MAC implementation.
*/
#include <assert.h>
#include "ssh.h"
bool ssh2_mac_verresult(ssh2_mac *mac, const void *candidate)
{
unsigned char correct[64]; /* at least as big as all known MACs */
bool toret;
assert(mac->vt->len <= sizeof(correct));
ssh2_mac_genresult(mac, correct);
toret = smemeq(correct, candidate, mac->vt->len);
smemclr(correct, sizeof(correct));
return toret;
}
static void ssh2_mac_prepare(ssh2_mac *mac, const void *blk, int len,
unsigned long seq)
{
ssh2_mac_start(mac);
put_uint32(mac, seq);
put_data(mac, blk, len);
}
void ssh2_mac_generate(ssh2_mac *mac, void *blk, int len, unsigned long seq)
{
ssh2_mac_prepare(mac, blk, len, seq);
ssh2_mac_genresult(mac, (unsigned char *)blk + len);
}
bool ssh2_mac_verify(
ssh2_mac *mac, const void *blk, int len, unsigned long seq)
{
ssh2_mac_prepare(mac, blk, len, seq);
return ssh2_mac_verresult(mac, (const unsigned char *)blk + len);
}