diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2018-07-26 12:05:43 -0400 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2018-08-02 15:33:23 -0400 |
commit | c571fe24d243bfe7017f0e67fe800b3cc2a1d1f7 (patch) | |
tree | b8abb465a55024df74cd7732fa97490a81c58024 | |
parent | c0f56b483aa09c99bfe97409a43ad786f33b8a5a (diff) |
libceph: factor out __ceph_x_decrypt()
Will be used for decrypting the server challenge which is only preceded
by ceph_x_encrypt_header.
Drop struct_v check to allow for extending ceph_x_encrypt_header in the
future.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Sage Weil <sage@redhat.com>
-rw-r--r-- | net/ceph/auth_x.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c index 6caac27fca85..cd1118d106a5 100644 --- a/net/ceph/auth_x.c +++ b/net/ceph/auth_x.c | |||
@@ -70,25 +70,40 @@ static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf, | |||
70 | return sizeof(u32) + ciphertext_len; | 70 | return sizeof(u32) + ciphertext_len; |
71 | } | 71 | } |
72 | 72 | ||
73 | static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p, | ||
74 | int ciphertext_len) | ||
75 | { | ||
76 | struct ceph_x_encrypt_header *hdr = p; | ||
77 | int plaintext_len; | ||
78 | int ret; | ||
79 | |||
80 | ret = ceph_crypt(secret, false, p, ciphertext_len, ciphertext_len, | ||
81 | &plaintext_len); | ||
82 | if (ret) | ||
83 | return ret; | ||
84 | |||
85 | if (le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) { | ||
86 | pr_err("%s bad magic\n", __func__); | ||
87 | return -EINVAL; | ||
88 | } | ||
89 | |||
90 | return plaintext_len - sizeof(*hdr); | ||
91 | } | ||
92 | |||
73 | static int ceph_x_decrypt(struct ceph_crypto_key *secret, void **p, void *end) | 93 | static int ceph_x_decrypt(struct ceph_crypto_key *secret, void **p, void *end) |
74 | { | 94 | { |
75 | struct ceph_x_encrypt_header *hdr = *p + sizeof(u32); | 95 | int ciphertext_len; |
76 | int ciphertext_len, plaintext_len; | ||
77 | int ret; | 96 | int ret; |
78 | 97 | ||
79 | ceph_decode_32_safe(p, end, ciphertext_len, e_inval); | 98 | ceph_decode_32_safe(p, end, ciphertext_len, e_inval); |
80 | ceph_decode_need(p, end, ciphertext_len, e_inval); | 99 | ceph_decode_need(p, end, ciphertext_len, e_inval); |
81 | 100 | ||
82 | ret = ceph_crypt(secret, false, *p, end - *p, ciphertext_len, | 101 | ret = __ceph_x_decrypt(secret, *p, ciphertext_len); |
83 | &plaintext_len); | 102 | if (ret < 0) |
84 | if (ret) | ||
85 | return ret; | 103 | return ret; |
86 | 104 | ||
87 | if (hdr->struct_v != 1 || le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) | ||
88 | return -EPERM; | ||
89 | |||
90 | *p += ciphertext_len; | 105 | *p += ciphertext_len; |
91 | return plaintext_len - sizeof(struct ceph_x_encrypt_header); | 106 | return ret; |
92 | 107 | ||
93 | e_inval: | 108 | e_inval: |
94 | return -EINVAL; | 109 | return -EINVAL; |