#define CEPH_CRYPTO_MD5_DIGESTSIZE 16
#define CEPH_CRYPTO_HMACSHA1_DIGESTSIZE 20
+#define CEPH_CRYPTO_SHA1_DIGESTSIZE 20
#ifdef USE_CRYPTOPP
# define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
// nothing
}
using CryptoPP::Weak::MD5;
+ using CryptoPP::SHA1;
class HMACSHA1: public CryptoPP::HMAC<CryptoPP::SHA1> {
public:
namespace ceph {
namespace crypto {
void init();
-
class MD5 {
private:
PK11Context *ctx;
Restart();
}
};
+#if 0
+ class Digest {
+ private:
+ PK11Context *ctx;
+ SECOidTag sec_type;
+ size_t digest_size;
+ public:
+ Digest (SECOidTag _type, size_t _digest_size) : sec_type(_type), digest_size(_digest_size) {
+ ctx = PK11_CreateDigestContext(_type);
+ assert(ctx);
+ Restart();
+ }
+ ~Digest () {
+ PK11_DestroyContext(ctx, PR_TRUE);
+ }
+ void Restart() {
+ SECStatus s;
+ s = PK11_DigestBegin(ctx);
+ assert(s == SECSuccess);
+ }
+ void Update (const byte *input, size_t length) {
+ SECStatus s;
+ s = PK11_DigestOp(ctx, input, length);
+ assert(s == SECSuccess);
+ }
+ void Final (byte *digest) {
+ SECStatus s;
+ unsigned int dummy;
+ s = PK11_DigestFinal(ctx, digest, &dummy, digest_size);
+ assert(s == SECSuccess);
+ assert(dummy == digest_size);
+ Restart();
+ }
+ };
+ class MD5 : public Digest {
+ public:
+ MD5 () : Digest(SEC_OID_MD5, CEPH_CRYPTO_MD5_DIGESTSIZE) { }
+ };
+ class SHA1 : public Digest {
+ public:
+ SHA1 () : Digest(SEC_OID_SHA1, CEPH_CRYPTO_SHA1_DIGESTSIZE) { }
+ };
+
+#endif
class HMACSHA1 {
private:
PK11SlotInfo *slot;
#include <map>
+#include "common/ceph_crypto.h"
+
+using ceph::crypto::MD5;
+// using ceph::crypto::SHA1;
+
/*
* long file names will have the following format:
*
}
#endif
+static inline void buf_to_hex(const unsigned char *buf, int len, char *str)
+{
+ int i;
+ str[0] = '\0';
+ for (i = 0; i < len; i++) {
+ sprintf(&str[i*2], "%02x", (int)buf[i]);
+ }
+}
+
static int hash_filename(const char *filename, char *hash, int buf_len)
{
if (buf_len < FILENAME_HASH_LEN + 1)
return -EINVAL;
- sprintf(hash, "zzz");
+
+ char buf[CEPH_CRYPTO_MD5_DIGESTSIZE];
+ char hex[CEPH_CRYPTO_MD5_DIGESTSIZE * 2];
+ MD5 h;
+ h.Update((const byte *)filename, strlen(filename));
+ h.Final((byte *)buf);
+
+ buf_to_hex((byte *)buf, (FILENAME_HASH_LEN + 1) / 2, hex);
+ strncpy(hash, hex, FILENAME_HASH_LEN);
+ hash[FILENAME_HASH_LEN] = '\0';
return 0;
}
// 012345678901234567890123456789012345678901234567890123456789
// yyyyyyyyyyyyyyyy.zzzzzzzz.a_s
-void FileStore::append_oname(const sobject_t &oid, char *s, int len)
+int FileStore::append_oname(const sobject_t &oid, char *s, int len)
{
//assert(sizeof(oid) == 28);
char *end = s + len;
i++;
}
+ int size = t - s;
+
if (oid.snap == CEPH_NOSNAP)
- snprintf(t, end - t, "_head");
+ size += snprintf(t, end - t, "_head");
else if (oid.snap == CEPH_SNAPDIR)
- snprintf(t, end - t, "_snapdir");
+ size += snprintf(t, end - t, "_snapdir");
else
- snprintf(t, end - t, "_%llx", (long long unsigned)oid.snap);
- //parse_object(t+1);
+ size += snprintf(t, end - t, "_%llx", (long long unsigned)oid.snap);
+
+ return size;
}
bool FileStore::parse_object(char *s, sobject_t& o)
filename = pathname + path_len;
*lfn = '\0';
- append_oname(oid, lfn, lfn_len);
+ int actual_len = append_oname(oid, lfn, lfn_len);
- if (oid.oid.name.size() < FILENAME_PREFIX_LEN) {
+ if (actual_len < (int)FILENAME_PREFIX_LEN) {
/* not a long file name, just build it as it is */
strncpy(filename, lfn, len - path_len);
*is_lfn = 0;
Finisher ondisk_finisher;
// helper fns
- void append_oname(const sobject_t &oid, char *s, int len);
- //void get_oname(sobject_t oid, char *s);
+ int append_oname(const sobject_t &oid, char *s, int len);
int get_cdir(coll_t cid, char *s, int len);
- void get_coname(coll_t cid, const sobject_t& oid, char *s, int len);
bool parse_object(char *s, sobject_t& o);
int lock_fsid();