25 #include <openssl/hmac.h>
28 const Com__Seagate__Kinetic__Proto__Message* proto,
48 Com__Seagate__Kinetic__Proto__Message* msg,
62 memcpy(msg->hmacauth->hmac.data, hmac->
data, hmac->
len);
63 msg->hmacauth->hmac.len = hmac->
len;
64 msg->hmacauth->has_hmac =
true;
79 if (!msg->has_authtype
81 || msg->hmacauth == NULL
82 || !msg->hmacauth->has_hmac
83 || msg->hmacauth->hmac.data == NULL
84 || msg->hmacauth->hmac.len == 0) {
90 if (msg->hmacauth->hmac.len == tempHMAC.
len) {
91 for (i = 0; i < tempHMAC.
len; i++) {
92 result |= msg->hmacauth->hmac.data[i] ^ tempHMAC.
data[i];
94 success = (result == 0);
98 LOG0(
"HMAC did not compare!");
99 ByteArray expected = {.
data = msg->hmacauth->hmac.data, .len = msg->hmacauth->hmac.len};
108 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
113 const Com__Seagate__Kinetic__Proto__Message* msg,
129 fprintf(stderr,
"\n\nUsing hmac key [%zd]: '%s' and length '", key.
len, key.
data);
130 for (
size_t i = 0; i <
sizeof(uint32_t); i++) {
131 fprintf(stderr,
"%02x", ((uint8_t *)&lenNBO)[i]);
134 fprintf(stderr,
"' on data: \n");
135 for (
size_t i = 0; i < msg->commandbytes.len; i++) {
136 fprintf(stderr,
"%02x", msg->commandbytes.data[i]);
137 if (i > 0 && (i & 15) == 15) { fprintf(stderr,
"\n"); }
139 fprintf(stderr,
"\n\n");
142 HMAC_Init_ex(&ctx, key.
data, key.
len, EVP_sha1(), NULL);
143 HMAC_Update(&ctx, (uint8_t*)&lenNBO,
sizeof(uint32_t));
144 HMAC_Update(&ctx, msg->commandbytes.data, msg->commandbytes.len);
145 HMAC_Final(&ctx, hmac->
data, &hmac->
len);
146 HMAC_CTX_cleanup(&ctx);
Structure for handling generic arrays of bytes.
bool KineticHMAC_Validate(const Com__Seagate__Kinetic__Proto__Message *msg, const ByteArray key)
uint32_t KineticNBO_FromHostU32(uint32_t valueHost)
#define KINETIC_HMAC_MAX_LEN
HMAC max length.
void KineticHMAC_Populate(KineticHMAC *hmac, Com__Seagate__Kinetic__Proto__Message *msg, const ByteArray key)
#define KINETIC_ASSERT(cond)
void KineticHMAC_Init(KineticHMAC *hmac, Com__Seagate__Kinetic__Proto__Command__Security__ACL__HMACAlgorithm algorithm)
size_t len
Number of bytes in the data field.
Com__Seagate__Kinetic__Proto__Command__Security__ACL__HMACAlgorithm
Com__Seagate__Kinetic__Proto__Command__Security__ACL__HMACAlgorithm algorithm
uint8_t data[KINETIC_HMAC_MAX_LEN]
uint8_t * data
Pointer to an allocated array of data bytes.
void KineticLogger_LogByteArray(int log_level, const char *title, ByteArray bytes)
static void KineticHMAC_Compute(KineticHMAC *hmac, const Com__Seagate__Kinetic__Proto__Message *proto, const ByteArray key)