From: Radoslaw Zarzynski Date: Sat, 9 Mar 2019 13:00:32 +0000 (+0100) Subject: auth: add hmac_sha256() to CryptoKey. X-Git-Tag: v14.2.0~23^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dc4dceffef75e116be6fecc9bb8fd258b5ecc678;p=ceph.git auth: add hmac_sha256() to CryptoKey. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/auth/Crypto.cc b/src/auth/Crypto.cc index bf9270a92e2c..8b355bf11423 100644 --- a/src/auth/Crypto.cc +++ b/src/auth/Crypto.cc @@ -131,6 +131,20 @@ std::size_t CryptoKeyHandler::decrypt( return todo_len; } +sha256_digest_t CryptoKeyHandler::hmac_sha256( + const ceph::bufferlist& in) const +{ + ceph::crypto::HMACSHA256 hmac((const unsigned char*)secret.c_str(), secret.length()); + + for (const auto& bptr : in.buffers()) { + hmac.Update((const unsigned char *)bptr.c_str(), bptr.length()); + } + sha256_digest_t ret; + hmac.Final(ret.v); + + return ret; +} + // --------------------------------------------------- class CryptoNoneKeyHandler : public CryptoKeyHandler { diff --git a/src/auth/Crypto.h b/src/auth/Crypto.h index 4cda0830343f..46323348bf57 100644 --- a/src/auth/Crypto.h +++ b/src/auth/Crypto.h @@ -80,6 +80,8 @@ public: const out_slice_t& out) const; virtual std::size_t decrypt(const in_slice_t& in, const out_slice_t& out) const; + + sha256_digest_t hmac_sha256(const ceph::bufferlist& in) const; }; /* @@ -169,6 +171,11 @@ public: return ckh->encrypt(in, out); } + sha256_digest_t hmac_sha256(CephContext*, const ceph::bufferlist& in) { + ceph_assert(ckh); + return ckh->hmac_sha256(in); + } + static constexpr std::size_t get_max_outbuf_size(std::size_t want_size) { return want_size + CryptoKeyHandler::MAX_BLOCK_SIZE; }