#ifdef USE_CRYPTOPP
// nothing
+ceph::crypto::HMACSHA1::~HMACSHA1()
+{
+}
+
#elif USE_NSS
void ceph::crypto::init() {
NSS_NoDB_Init(NULL);
}
+ceph::crypto::HMACSHA1::~HMACSHA1()
+{
+ PK11_DestroyContext(ctx, PR_TRUE);
+ PK11_FreeSymKey(symkey);
+ PK11_FreeSlot(slot);
+}
+
#else
# error "No supported crypto implementation found."
#endif
#include "acconfig.h"
+#define CEPH_CRYPTO_MD5_DIGESTSIZE 16
+#define CEPH_CRYPTO_HMACSHA1_DIGESTSIZE 20
+
#ifdef USE_CRYPTOPP
# define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <string.h>
: CryptoPP::HMAC<CryptoPP::SHA1>(key, length)
{
}
+ ~HMACSHA1();
};
}
}
private:
PK11Context *ctx;
public:
- static const int DIGESTSIZE = 16;
MD5 () {
ctx = PK11_CreateDigestContext(SEC_OID_MD5);
assert(ctx);
void Final (byte *digest) {
SECStatus s;
unsigned int dummy;
- s = PK11_DigestFinal(ctx, digest, &dummy, DIGESTSIZE);
+ s = PK11_DigestFinal(ctx, digest, &dummy, CEPH_CRYPTO_MD5_DIGESTSIZE);
assert(s == SECSuccess);
- assert(dummy == (unsigned int)DIGESTSIZE);
+ assert(dummy == CEPH_CRYPTO_MD5_DIGESTSIZE);
Restart();
}
};
PK11SymKey *symkey;
PK11Context *ctx;
public:
- static const int DIGESTSIZE = 20;
+ static const int DIGESTSIZE;
HMACSHA1 (const byte *key, size_t length) {
slot = PK11_GetBestSlot(CKM_SHA_1_HMAC, NULL);
assert(slot);
assert(ctx);
Restart();
}
- ~HMACSHA1 () {
- PK11_DestroyContext(ctx, PR_TRUE);
- PK11_FreeSymKey(symkey);
- PK11_FreeSlot(slot);
- }
+ ~HMACSHA1 ();
void Restart() {
SECStatus s;
s = PK11_DigestBegin(ctx);
void Final (byte *digest) {
SECStatus s;
unsigned int dummy;
- s = PK11_DigestFinal(ctx, digest, &dummy, DIGESTSIZE);
+ s = PK11_DigestFinal(ctx, digest, &dummy, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
assert(s == SECSuccess);
- assert(dummy == (unsigned int)DIGESTSIZE);
+ assert(dummy == CEPH_CRYPTO_HMACSHA1_DIGESTSIZE);
Restart();
}
};
const char *msg, int msg_len,
char *dest, int *len) /* dest should be large enough to hold result */
{
- if (*len < HMACSHA1::DIGESTSIZE)
+ if (*len < CEPH_CRYPTO_HMACSHA1_DIGESTSIZE)
return -EINVAL;
- char hex_str[HMACSHA1::DIGESTSIZE * 2 + 1];
- char key_buf[HMACSHA1::DIGESTSIZE];
- key_len = max(key_len, HMACSHA1::DIGESTSIZE);
+ 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);
memcpy(key_buf, key, key_len);
- memset(key_buf + key_len, 0, HMACSHA1::DIGESTSIZE - 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 = HMACSHA1::DIGESTSIZE;
+ *len = CEPH_CRYPTO_HMACSHA1_DIGESTSIZE;
buf_to_hex((unsigned char *)dest, *len, hex_str);
size_t size;
time_t mtime;
// two md5 digests and a terminator
- char etag[ceph::crypto::MD5::DIGESTSIZE * 2 + 1];
+ char etag[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
void encode(bufferlist& bl) const {
__u8 struct_v = 1;
std::string name;
size_t size;
time_t mtime;
- char etag[MD5::DIGESTSIZE * 2 + 1];
+ char etag[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
uint64_t count;
void encode(bufferlist& bl) const {
goto done;
}
- char supplied_md5_bin[MD5::DIGESTSIZE + 1];
- char supplied_md5[MD5::DIGESTSIZE * 2 + 1];
- char calc_md5[MD5::DIGESTSIZE * 2 + 1];
- unsigned char m[MD5::DIGESTSIZE];
+ char supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1];
+ char supplied_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
+ char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
+ unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE];
if (supplied_md5_b64) {
RGW_LOG(15) << "supplied_md5_b64=" << supplied_md5_b64 << endl;
- ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[MD5::DIGESTSIZE + 1],
+ ret = ceph_unarmor(supplied_md5_bin, &supplied_md5_bin[CEPH_CRYPTO_MD5_DIGESTSIZE + 1],
supplied_md5_b64, supplied_md5_b64 + strlen(supplied_md5_b64));
RGW_LOG(15) << "ceph_armor ret=" << ret << endl;
- if (ret != MD5::DIGESTSIZE) {
+ if (ret != CEPH_CRYPTO_MD5_DIGESTSIZE) {
err.code = "InvalidDigest";
ret = -EINVAL;
goto done;
}
- buf_to_hex((const unsigned char *)supplied_md5_bin, MD5::DIGESTSIZE, supplied_md5);
+ buf_to_hex((const unsigned char *)supplied_md5_bin, CEPH_CRYPTO_MD5_DIGESTSIZE, supplied_md5);
RGW_LOG(15) << "supplied_md5=" << supplied_md5 << endl;
}
hash.Final(m);
- buf_to_hex(m, MD5::DIGESTSIZE, calc_md5);
+ buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5);
if (supplied_md5_b64 && strcmp(calc_md5, supplied_md5)) {
err.code = "BadDigest";
::encode(nonce, bl);
::encode(expiration, bl);
- bufferptr p(HMACSHA1::DIGESTSIZE);
+ 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);
RGW_LOG(0) << "bl=" << buf << std::endl;
- char k[HMACSHA1::DIGESTSIZE];
+ char k[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE];
memset(k, 0, sizeof(k));
const char *s = key.c_str();
for (int i = 0; i < (int)key.length(); i++, s++) {
- k[i % HMACSHA1::DIGESTSIZE] |= *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 != HMACSHA1::DIGESTSIZE)
+ if (len != CEPH_CRYPTO_HMACSHA1_DIGESTSIZE)
return -EINVAL;
bl.append(p);
const char *key = s->user.secret_key.c_str();
int key_len = strlen(key);
- char hmac_sha1[HMACSHA1::DIGESTSIZE];
+ 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;