From: Colin Patrick McCabe Date: Wed, 23 Mar 2011 22:23:57 +0000 (-0700) Subject: ceph_crypto: fix undefined references X-Git-Tag: v0.26~59 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6346702371d1a9e6c2699af07166e1eccd8f6441;p=ceph.git ceph_crypto: fix undefined references Signed-off-by: Colin McCabe --- diff --git a/src/common/ceph_crypto.cc b/src/common/ceph_crypto.cc index a625732a5be49..31b6f572516f5 100644 --- a/src/common/ceph_crypto.cc +++ b/src/common/ceph_crypto.cc @@ -2,12 +2,23 @@ #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 diff --git a/src/common/ceph_crypto.h b/src/common/ceph_crypto.h index bf4dbfc7f529e..abaf95cfdec9b 100644 --- a/src/common/ceph_crypto.h +++ b/src/common/ceph_crypto.h @@ -3,6 +3,9 @@ #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 @@ -22,6 +25,7 @@ namespace ceph { : CryptoPP::HMAC(key, length) { } + ~HMACSHA1(); }; } } @@ -48,7 +52,6 @@ namespace ceph { private: PK11Context *ctx; public: - static const int DIGESTSIZE = 16; MD5 () { ctx = PK11_CreateDigestContext(SEC_OID_MD5); assert(ctx); @@ -70,9 +73,9 @@ namespace ceph { 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(); } }; @@ -83,7 +86,7 @@ namespace ceph { 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); @@ -102,11 +105,7 @@ namespace ceph { assert(ctx); Restart(); } - ~HMACSHA1 () { - PK11_DestroyContext(ctx, PR_TRUE); - PK11_FreeSymKey(symkey); - PK11_FreeSlot(slot); - } + ~HMACSHA1 (); void Restart() { SECStatus s; s = PK11_DigestBegin(ctx); @@ -120,9 +119,9 @@ namespace ceph { 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(); } }; diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index a29c17adfc599..60bf7ac58ecb6 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -29,19 +29,19 @@ 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 */ { - 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); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index f6ce42ca2cbaf..4ff8637e03e59 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -262,7 +262,7 @@ struct RGWObjEnt { 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; @@ -292,7 +292,7 @@ struct RGWBucketEnt { 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 { diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index f39ee29923984..7bb653d7842a7 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -353,23 +353,23 @@ void RGWPutObj::execute() 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; } @@ -388,7 +388,7 @@ void RGWPutObj::execute() 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"; diff --git a/src/rgw/rgw_os_auth.cc b/src/rgw/rgw_os_auth.cc index 8f850fae05ecf..fe2e4d94ec5ec 100644 --- a/src/rgw/rgw_os_auth.cc +++ b/src/rgw/rgw_os_auth.cc @@ -16,25 +16,25 @@ static int build_token(string& os_user, string& key, uint64_t nonce, utime_t& ex ::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); diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index cb960e4e9e05f..e9c2a07559aaa 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -414,7 +414,7 @@ bool RGWHandler_REST_S3::authorize(struct req_state *s) 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;