From 52e3cb77ef0d3393e21a8ec7b507755c7ae56088 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 17 Jan 2018 20:43:38 -0500 Subject: [PATCH] common: remove typedef for byte Signed-off-by: Casey Bodley --- src/common/ceph_crypto.h | 17 +++++++-------- src/os/filestore/LFNIndex.cc | 6 +++--- src/rgw/rgw_crypt.cc | 10 ++++----- src/rgw/rgw_file.cc | 2 +- src/rgw/rgw_keystone.cc | 2 +- src/rgw/rgw_op.cc | 18 ++++++++-------- src/rgw/rgw_op.h | 2 +- src/rgw/rgw_rados.cc | 8 ++++---- src/rgw/rgw_rest_swift.cc | 2 +- src/rgw/rgw_torrent.cc | 8 ++++---- src/test/ceph_crypto.cc | 40 ++++++++++++++++++------------------ 11 files changed, 56 insertions(+), 59 deletions(-) diff --git a/src/common/ceph_crypto.h b/src/common/ceph_crypto.h index 05d686392e2f..a5d781eccbcf 100644 --- a/src/common/ceph_crypto.h +++ b/src/common/ceph_crypto.h @@ -21,9 +21,6 @@ // This assert MUST NOT be compiled out, even on non-debug builds. # include "include/assert.h" -// ugly bit of CryptoPP that we have to emulate here :( -typedef unsigned char byte; - namespace ceph { namespace crypto { void assert_init(); @@ -47,14 +44,14 @@ namespace ceph { s = PK11_DigestBegin(ctx); assert(s == SECSuccess); } - void Update (const ::byte *input, size_t length) { + void Update (const unsigned char *input, size_t length) { if (length) { SECStatus s; s = PK11_DigestOp(ctx, input, length); assert(s == SECSuccess); } } - void Final (::byte *digest) { + void Final (unsigned char *digest) { SECStatus s; unsigned int dummy; s = PK11_DigestFinal(ctx, digest, &dummy, digest_size); @@ -85,7 +82,7 @@ namespace ceph { PK11Context *ctx; unsigned int digest_size; public: - HMAC (CK_MECHANISM_TYPE cktype, unsigned int digestsize, const ::byte *key, size_t length) { + HMAC (CK_MECHANISM_TYPE cktype, unsigned int digestsize, const unsigned char *key, size_t length) { digest_size = digestsize; slot = PK11_GetBestSlot(cktype, NULL); assert(slot); @@ -110,12 +107,12 @@ namespace ceph { s = PK11_DigestBegin(ctx); assert(s == SECSuccess); } - void Update (const ::byte *input, size_t length) { + void Update (const unsigned char *input, size_t length) { SECStatus s; s = PK11_DigestOp(ctx, input, length); assert(s == SECSuccess); } - void Final (::byte *digest) { + void Final (unsigned char *digest) { SECStatus s; unsigned int dummy; s = PK11_DigestFinal(ctx, digest, &dummy, digest_size); @@ -127,12 +124,12 @@ namespace ceph { class HMACSHA1 : public HMAC { public: - HMACSHA1 (const ::byte *key, size_t length) : HMAC(CKM_SHA_1_HMAC, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE, key, length) { } + HMACSHA1 (const unsigned char *key, size_t length) : HMAC(CKM_SHA_1_HMAC, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE, key, length) { } }; class HMACSHA256 : public HMAC { public: - HMACSHA256 (const ::byte *key, size_t length) : HMAC(CKM_SHA256_HMAC, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE, key, length) { } + HMACSHA256 (const unsigned char *key, size_t length) : HMAC(CKM_SHA256_HMAC, CEPH_CRYPTO_HMACSHA256_DIGESTSIZE, key, length) { } }; } } diff --git a/src/os/filestore/LFNIndex.cc b/src/os/filestore/LFNIndex.cc index 9591d66e7f44..b55658a1469b 100644 --- a/src/os/filestore/LFNIndex.cc +++ b/src/os/filestore/LFNIndex.cc @@ -1279,10 +1279,10 @@ int LFNIndex::hash_filename(const char *filename, char *hash, int buf_len) char hex[FILENAME_LFN_DIGEST_SIZE * 2]; SHA1 h; - h.Update((const ::byte *)filename, strlen(filename)); - h.Final((::byte *)buf); + h.Update((const unsigned char *)filename, strlen(filename)); + h.Final((unsigned char *)buf); - buf_to_hex((::byte *)buf, (FILENAME_HASH_LEN + 1) / 2, hex); + buf_to_hex((unsigned char *)buf, (FILENAME_HASH_LEN + 1) / 2, hex); strncpy(hash, hex, FILENAME_HASH_LEN); hash[FILENAME_HASH_LEN] = '\0'; return 0; diff --git a/src/rgw/rgw_crypt.cc b/src/rgw/rgw_crypt.cc index 0d155f5782b4..8af6ce7a9553 100644 --- a/src/rgw/rgw_crypt.cc +++ b/src/rgw/rgw_crypt.cc @@ -125,7 +125,7 @@ public: return encrypt(input, in_ofs, size, output, stream_offset); } - void prepare_iv(::byte iv[AES_256_IVSIZE], off_t offset) { + void prepare_iv(unsigned char iv[AES_256_IVSIZE], off_t offset) { off_t index = offset / AES_256_IVSIZE; off_t i = AES_256_IVSIZE - 1; unsigned int val; @@ -424,7 +424,7 @@ public: } - void prepare_iv(::byte (&iv)[AES_256_IVSIZE], off_t offset) { + void prepare_iv(unsigned char (&iv)[AES_256_IVSIZE], off_t offset) { off_t index = offset / AES_256_IVSIZE; off_t i = AES_256_IVSIZE - 1; unsigned int val; @@ -984,8 +984,8 @@ int rgw_s3_prepare_encrypt(struct req_state* s, } MD5 key_hash; - ::byte key_hash_res[CEPH_CRYPTO_MD5_DIGESTSIZE]; - key_hash.Update(reinterpret_cast(key_bin.c_str()), key_bin.size()); + unsigned char key_hash_res[CEPH_CRYPTO_MD5_DIGESTSIZE]; + key_hash.Update(reinterpret_cast(key_bin.c_str()), key_bin.size()); key_hash.Final(key_hash_res); if (memcmp(key_hash_res, keymd5_bin.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE) != 0) { @@ -1221,7 +1221,7 @@ int rgw_s3_prepare_decrypt(struct req_state* s, MD5 key_hash; uint8_t key_hash_res[CEPH_CRYPTO_MD5_DIGESTSIZE]; - key_hash.Update(reinterpret_cast(key_bin.c_str()), key_bin.size()); + key_hash.Update(reinterpret_cast(key_bin.c_str()), key_bin.size()); key_hash.Final(key_hash_res); if ((memcmp(key_hash_res, keymd5_bin.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE) != 0) || diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index d37f05be30c6..806d95d361c9 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1365,7 +1365,7 @@ namespace rgw { if (need_to_wait) { orig_data = data; } - hash.Update((const ::byte *)data.c_str(), data.length()); + hash.Update((const unsigned char *)data.c_str(), data.length()); op_ret = put_data_and_throttle(filter, data, ofs, need_to_wait); if (op_ret < 0) { if (!need_to_wait || op_ret != -EEXIST) { diff --git a/src/rgw/rgw_keystone.cc b/src/rgw/rgw_keystone.cc index eea1d2922c7c..2878cf70453a 100644 --- a/src/rgw/rgw_keystone.cc +++ b/src/rgw/rgw_keystone.cc @@ -113,7 +113,7 @@ void rgw_get_token_id(const string& token, string& token_id) unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE]; MD5 hash; - hash.Update((const ::byte *)token.c_str(), token.size()); + hash.Update((const unsigned char *)token.c_str(), token.size()); hash.Final(m); char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 1710bdfd54cf..ab90b5538533 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1180,7 +1180,7 @@ static int iterate_user_manifest_parts(CephContext * const cct, obj_ofs += obj_size; if (pobj_sum) { - etag_sum.Update((const ::byte *)ent.meta.etag.c_str(), + etag_sum.Update((const unsigned char *)ent.meta.etag.c_str(), ent.meta.etag.length()); } @@ -1518,7 +1518,7 @@ int RGWGetObj::handle_slo_manifest(bufferlist& bl) << " etag=" << part.etag << dendl; - etag_sum.Update((const ::byte *)entry.etag.c_str(), + etag_sum.Update((const unsigned char *)entry.etag.c_str(), entry.etag.length()); slo_parts[total_len] = part; @@ -3424,7 +3424,7 @@ void RGWPutObj::execute() } if (need_calc_md5) { - hash.Update((const ::byte *)data.c_str(), data.length()); + hash.Update((const unsigned char *)data.c_str(), data.length()); } /* update torrrent */ @@ -3570,7 +3570,7 @@ void RGWPutObj::execute() encode(*slo_info, manifest_bl); emplace_attr(RGW_ATTR_SLO_MANIFEST, std::move(manifest_bl)); - hash.Update((::byte *)slo_info->raw_data, slo_info->raw_data_len); + hash.Update((unsigned char *)slo_info->raw_data, slo_info->raw_data_len); complete_etag(hash, &etag); ldout(s->cct, 10) << __func__ << ": calculated md5 for user manifest: " << etag << dendl; } @@ -3760,7 +3760,7 @@ void RGWPostObj::execute() break; } - hash.Update((const ::byte *)data.c_str(), data.length()); + hash.Update((const unsigned char *)data.c_str(), data.length()); op_ret = put_data_and_throttle(filter, data, ofs, false); ofs += len; @@ -4835,7 +4835,7 @@ void RGWPutLC::execute() MD5 data_hash; unsigned char data_hash_res[CEPH_CRYPTO_MD5_DIGESTSIZE]; - data_hash.Update(reinterpret_cast(data), len); + data_hash.Update(reinterpret_cast(data), len); data_hash.Final(data_hash_res); if (memcmp(data_hash_res, content_md5_bin.c_str(), CEPH_CRYPTO_MD5_DIGESTSIZE) != 0) { @@ -5420,7 +5420,7 @@ void RGWCompleteMultipart::execute() hex_to_buf(obj_iter->second.etag.c_str(), petag, CEPH_CRYPTO_MD5_DIGESTSIZE); - hash.Update((const ::byte *)petag, sizeof(petag)); + hash.Update((const unsigned char *)petag, sizeof(petag)); RGWUploadPartInfo& obj_part = obj_iter->second; @@ -5477,7 +5477,7 @@ void RGWCompleteMultipart::execute() accounted_size += obj_part.accounted_size; } } while (truncated); - hash.Final((::byte *)final_etag); + hash.Final((unsigned char *)final_etag); buf_to_hex((unsigned char *)final_etag, sizeof(final_etag), final_etag_str); snprintf(&final_etag_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2], sizeof(final_etag_str) - CEPH_CRYPTO_MD5_DIGESTSIZE * 2, @@ -6403,7 +6403,7 @@ int RGWBulkUploadOp::handle_file(const boost::string_ref path, op_ret = len; return op_ret; } else if (len > 0) { - hash.Update((const ::byte *)data.c_str(), data.length()); + hash.Update((const unsigned char *)data.c_str(), data.length()); op_ret = put_data_and_throttle(filter, data, ofs, false); if (op_ret < 0) { ldout(s->cct, 20) << "processor->thottle_data() returned ret=" diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 50fbb6865f48..801c6d20ce97 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -2038,7 +2038,7 @@ static inline void complete_etag(MD5& hash, string *etag) char etag_buf[CEPH_CRYPTO_MD5_DIGESTSIZE]; char etag_buf_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 16]; - hash.Final((::byte *)etag_buf); + hash.Final((unsigned char *)etag_buf); buf_to_hex((const unsigned char *)etag_buf, CEPH_CRYPTO_MD5_DIGESTSIZE, etag_buf_str); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 16346d77b39d..583c7858a8f4 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1929,7 +1929,7 @@ static uint32_t gen_short_zone_id(const std::string zone_id) { unsigned char md5[CEPH_CRYPTO_MD5_DIGESTSIZE]; MD5 hash; - hash.Update((const ::byte *)zone_id.c_str(), zone_id.size()); + hash.Update((const unsigned char *)zone_id.c_str(), zone_id.size()); hash.Final(md5); uint32_t short_id; @@ -4008,7 +4008,7 @@ int RGWRados::replace_region_with_zonegroup() unsigned char md5[CEPH_CRYPTO_MD5_DIGESTSIZE]; char md5_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; MD5 hash; - hash.Update((const ::byte *)new_realm_name.c_str(), new_realm_name.length()); + hash.Update((const unsigned char *)new_realm_name.c_str(), new_realm_name.length()); hash.Final(md5); buf_to_hex(md5, CEPH_CRYPTO_MD5_DIGESTSIZE, md5_str); string new_realm_id(md5_str); @@ -9081,12 +9081,12 @@ static void generate_fake_tag(RGWRados *store, map& attrset, unsigned char md5[CEPH_CRYPTO_MD5_DIGESTSIZE]; char md5_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; MD5 hash; - hash.Update((const ::byte *)manifest_bl.c_str(), manifest_bl.length()); + hash.Update((const unsigned char *)manifest_bl.c_str(), manifest_bl.length()); map::iterator iter = attrset.find(RGW_ATTR_ETAG); if (iter != attrset.end()) { bufferlist& bl = iter->second; - hash.Update((const ::byte *)bl.c_str(), bl.length()); + hash.Update((const unsigned char *)bl.c_str(), bl.length()); } hash.Final(md5); diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index a21f31bfea8e..caf5260864b3 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -889,7 +889,7 @@ int RGWPutObj_ObjStore_SWIFT::get_params() MD5 etag_sum; uint64_t total_size = 0; for (const auto& entry : slo_info->entries) { - etag_sum.Update((const ::byte *)entry.etag.c_str(), + etag_sum.Update((const unsigned char *)entry.etag.c_str(), entry.etag.length()); total_size += entry.size_bytes; diff --git a/src/rgw/rgw_torrent.cc b/src/rgw/rgw_torrent.cc index 7df0f0cf7360..1ba9595b1e02 100644 --- a/src/rgw/rgw_torrent.cc +++ b/src/rgw/rgw_torrent.cc @@ -156,8 +156,8 @@ void seed::sha1(SHA1 *h, bufferlist &bl, off_t bl_len) for (off_t i = 0; i < num; i++) { memset(sha, 0x00, sizeof(sha)); - h->Update((::byte *)pstr, info.piece_length); - h->Final((::byte *)sha); + h->Update((unsigned char *)pstr, info.piece_length); + h->Final((unsigned char *)sha); set_info_pieces(sha); pstr += info.piece_length; } @@ -166,8 +166,8 @@ void seed::sha1(SHA1 *h, bufferlist &bl, off_t bl_len) if (0 != remain) { memset(sha, 0x00, sizeof(sha)); - h->Update((::byte *)pstr, remain); - h->Final((::byte *)sha); + h->Update((unsigned char *)pstr, remain); + h->Final((unsigned char *)sha); set_info_pieces(sha); } } diff --git a/src/test/ceph_crypto.cc b/src/test/ceph_crypto.cc index 030e8a87c1c3..aa76ee8313fe 100644 --- a/src/test/ceph_crypto.cc +++ b/src/test/ceph_crypto.cc @@ -14,7 +14,7 @@ public: TEST(MD5, Simple) { ceph::crypto::MD5 h; - h.Update((const ::byte*)"foo", 3); + h.Update((const unsigned char*)"foo", 3); unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); int err; @@ -28,11 +28,11 @@ TEST(MD5, Simple) { TEST(MD5, MultiUpdate) { ceph::crypto::MD5 h; - h.Update((const ::byte*)"", 0); - h.Update((const ::byte*)"fo", 2); - h.Update((const ::byte*)"", 0); - h.Update((const ::byte*)"o", 1); - h.Update((const ::byte*)"", 0); + h.Update((const unsigned char*)"", 0); + h.Update((const unsigned char*)"fo", 2); + h.Update((const unsigned char*)"", 0); + h.Update((const unsigned char*)"o", 1); + h.Update((const unsigned char*)"", 0); unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); int err; @@ -46,9 +46,9 @@ TEST(MD5, MultiUpdate) { TEST(MD5, Restart) { ceph::crypto::MD5 h; - h.Update((const ::byte*)"bar", 3); + h.Update((const unsigned char*)"bar", 3); h.Restart(); - h.Update((const ::byte*)"foo", 3); + h.Update((const unsigned char*)"foo", 3); unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); int err; @@ -61,8 +61,8 @@ TEST(MD5, Restart) { } TEST(HMACSHA1, Simple) { - ceph::crypto::HMACSHA1 h((const ::byte*)"sekrit", 6); - h.Update((const ::byte*)"foo", 3); + ceph::crypto::HMACSHA1 h((const unsigned char*)"sekrit", 6); + h.Update((const unsigned char*)"foo", 3); unsigned char digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE]; h.Final(digest); int err; @@ -75,12 +75,12 @@ TEST(HMACSHA1, Simple) { } TEST(HMACSHA1, MultiUpdate) { - ceph::crypto::HMACSHA1 h((const ::byte*)"sekrit", 6); - h.Update((const ::byte*)"", 0); - h.Update((const ::byte*)"fo", 2); - h.Update((const ::byte*)"", 0); - h.Update((const ::byte*)"o", 1); - h.Update((const ::byte*)"", 0); + ceph::crypto::HMACSHA1 h((const unsigned char*)"sekrit", 6); + h.Update((const unsigned char*)"", 0); + h.Update((const unsigned char*)"fo", 2); + h.Update((const unsigned char*)"", 0); + h.Update((const unsigned char*)"o", 1); + h.Update((const unsigned char*)"", 0); unsigned char digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE]; h.Final(digest); int err; @@ -93,10 +93,10 @@ TEST(HMACSHA1, MultiUpdate) { } TEST(HMACSHA1, Restart) { - ceph::crypto::HMACSHA1 h((const ::byte*)"sekrit", 6); - h.Update((const ::byte*)"bar", 3); + ceph::crypto::HMACSHA1 h((const unsigned char*)"sekrit", 6); + h.Update((const unsigned char*)"bar", 3); h.Restart(); - h.Update((const ::byte*)"foo", 3); + h.Update((const unsigned char*)"foo", 3); unsigned char digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE]; h.Final(digest); int err; @@ -133,7 +133,7 @@ void do_simple_crypto() { // not exit status 0 ceph::crypto::init(g_ceph_context); ceph::crypto::MD5 h; - h.Update((const ::byte*)"foo", 3); + h.Update((const unsigned char*)"foo", 3); unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); exit(0); -- 2.47.3