dco_win: In dco_new_key, document size assumptions for the integer casts

And make all casts explicit so that compiler doesn't complain.

Change-Id: I612bf3b1c56d70a89fc04fad6fe36fd9fadfd258
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: MaxF <max@max-fillinger.net>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1221
Message-Id: <20250926165151.1502-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33229.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Frank Lichtenheld 2025-09-26 18:51:46 +02:00 committed by Gert Doering
parent 2682fb541e
commit e77c34370d

View file

@ -525,11 +525,6 @@ dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_interval, in
return 0;
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
int
dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slot_t slot,
const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const uint8_t *decrypt_key,
@ -540,21 +535,23 @@ dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slot_t s
const int nonce_len = 8;
size_t key_len = cipher_kt_key_size(ciphername);
ASSERT(key_len <= 32);
OVPN_CRYPTO_DATA crypto_data;
ZeroMemory(&crypto_data, sizeof(crypto_data));
crypto_data.CipherAlg = dco_get_cipher(ciphername);
crypto_data.KeyId = keyid;
ASSERT(keyid > 0 && keyid <= UCHAR_MAX);
crypto_data.KeyId = (unsigned char)keyid;
crypto_data.PeerId = peerid;
crypto_data.KeySlot = slot;
CopyMemory(crypto_data.Encrypt.Key, encrypt_key, key_len);
crypto_data.Encrypt.KeyLen = (char)key_len;
crypto_data.Encrypt.KeyLen = (unsigned char)key_len;
CopyMemory(crypto_data.Encrypt.NonceTail, encrypt_iv, nonce_len);
CopyMemory(crypto_data.Decrypt.Key, decrypt_key, key_len);
crypto_data.Decrypt.KeyLen = (char)key_len;
crypto_data.Decrypt.KeyLen = (unsigned char)key_len;
CopyMemory(crypto_data.Decrypt.NonceTail, decrypt_iv, nonce_len);
ASSERT(crypto_data.CipherAlg > 0);
@ -570,10 +567,6 @@ dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slot_t s
return 0;
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
int
dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot)
{