/*
* calculate the sha1 value of a given msg and key
*/
-int calc_hmac_sha1(const char *key, int key_len,
- const char *msg, int msg_len,
- char *dest, int *len) /* dest should be large enough to hold result */
+void calc_hmac_sha1(const char *key, int key_len,
+ const char *msg, int msg_len, char *dest)
+/* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
{
- if (*len < CEPH_CRYPTO_HMACSHA1_DIGESTSIZE)
- return -EINVAL;
-
- char hex_str[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE * 2 + 1];
char key_buf[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE];
- key_len = max(key_len, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
+ memset(key_buf, 0, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
memcpy(key_buf, key, key_len);
- memset(key_buf + key_len, 0, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE - key_len);
HMACSHA1 hmac((const unsigned char *)key, key_len);
hmac.Update((const unsigned char *)msg, msg_len);
hmac.Final((unsigned char *)dest);
- *len = CEPH_CRYPTO_HMACSHA1_DIGESTSIZE;
- buf_to_hex((unsigned char *)dest, *len, hex_str);
+ char hex_str[(CEPH_CRYPTO_HMACSHA1_DIGESTSIZE * 2) + 1];
+ buf_to_hex((unsigned char *)dest, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE, hex_str);
RGW_LOG(15) << "hmac=" << hex_str << endl;
-
- return 0;
}
int NameVal::parse()
* by converting %-escaped strings into characters, etc*/
extern bool url_decode(string& src_str, string& dest_str);
-extern int calc_hmac_sha1(const char *key, int key_len,
- const char *msg, int msg_len,
- char *dest, int *len); /* dest should be large enough to hold result */
+extern void calc_hmac_sha1(const char *key, int key_len,
+ const char *msg, int msg_len, char *dest);
+/* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
+
/* loglevel of the gateway */
extern int rgw_log_level;
::encode(expiration, bl);
bufferptr p(CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
- int len = p.length();
char buf[bl.length() * 2 + 1];
buf_to_hex((const unsigned char *)bl.c_str(), bl.length(), buf);
for (int i = 0; i < (int)key.length(); i++, s++) {
k[i % CEPH_CRYPTO_HMACSHA1_DIGESTSIZE] |= *s;
}
- int ret = calc_hmac_sha1(k, sizeof(k), bl.c_str(), bl.length(),
- p.c_str(), &len);
- if (ret < 0)
- return ret;
-
- if (len != CEPH_CRYPTO_HMACSHA1_DIGESTSIZE)
- return -EINVAL;
+ calc_hmac_sha1(k, sizeof(k), bl.c_str(), bl.length(), p.c_str());
bl.append(p);
int key_len = strlen(key);
char hmac_sha1[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE];
- int len = sizeof(hmac_sha1);
- if (calc_hmac_sha1(key, key_len, auth_hdr.c_str(), auth_hdr.size(), hmac_sha1, &len) < 0)
- return false;
+ calc_hmac_sha1(key, key_len, auth_hdr.c_str(), auth_hdr.size(), hmac_sha1);
char b64[64]; /* 64 is really enough */
- int ret = ceph_armor(b64, &b64[sizeof(b64)], hmac_sha1, &hmac_sha1[len]);
+ int ret = ceph_armor(b64, b64 + 64, hmac_sha1,
+ hmac_sha1 + CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
if (ret < 0) {
RGW_LOG(10) << "ceph_armor failed" << endl;
return false;