Skip to content

Commit 4eb4517

Browse files
committed
libceph: tweak calcu_signature() a little
- replace an ad-hoc array with a struct - rename to calc_signature() for consistency Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Sage Weil <sage@redhat.com>
1 parent 7882a26 commit 4eb4517

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

net/ceph/auth_x.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -707,35 +707,48 @@ static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac,
707707
invalidate_ticket(ac, CEPH_ENTITY_TYPE_AUTH);
708708
}
709709

710-
static int calcu_signature(struct ceph_x_authorizer *au,
711-
struct ceph_msg *msg, __le64 *sig)
710+
static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg,
711+
__le64 *psig)
712712
{
713-
int ret;
714713
char tmp_enc[40];
715-
__le32 tmp[5] = {
716-
cpu_to_le32(16), msg->hdr.crc, msg->footer.front_crc,
717-
msg->footer.middle_crc, msg->footer.data_crc,
718-
};
719-
ret = ceph_x_encrypt(&au->session_key, &tmp, sizeof(tmp),
714+
struct {
715+
__le32 len;
716+
__le32 header_crc;
717+
__le32 front_crc;
718+
__le32 middle_crc;
719+
__le32 data_crc;
720+
} __packed sigblock;
721+
int ret;
722+
723+
sigblock.len = cpu_to_le32(4*sizeof(u32));
724+
sigblock.header_crc = msg->hdr.crc;
725+
sigblock.front_crc = msg->footer.front_crc;
726+
sigblock.middle_crc = msg->footer.middle_crc;
727+
sigblock.data_crc = msg->footer.data_crc;
728+
ret = ceph_x_encrypt(&au->session_key, &sigblock, sizeof(sigblock),
720729
tmp_enc, sizeof(tmp_enc));
721730
if (ret < 0)
722731
return ret;
723-
*sig = *(__le64*)(tmp_enc + 4);
732+
733+
*psig = *(__le64 *)(tmp_enc + sizeof(u32));
724734
return 0;
725735
}
726736

727737
static int ceph_x_sign_message(struct ceph_auth_handshake *auth,
728738
struct ceph_msg *msg)
729739
{
740+
__le64 sig;
730741
int ret;
731742

732743
if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN))
733744
return 0;
734745

735-
ret = calcu_signature((struct ceph_x_authorizer *)auth->authorizer,
736-
msg, &msg->footer.sig);
737-
if (ret < 0)
746+
ret = calc_signature((struct ceph_x_authorizer *)auth->authorizer,
747+
msg, &sig);
748+
if (ret)
738749
return ret;
750+
751+
msg->footer.sig = sig;
739752
msg->footer.flags |= CEPH_MSG_FOOTER_SIGNED;
740753
return 0;
741754
}
@@ -749,9 +762,9 @@ static int ceph_x_check_message_signature(struct ceph_auth_handshake *auth,
749762
if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN))
750763
return 0;
751764

752-
ret = calcu_signature((struct ceph_x_authorizer *)auth->authorizer,
753-
msg, &sig_check);
754-
if (ret < 0)
765+
ret = calc_signature((struct ceph_x_authorizer *)auth->authorizer,
766+
msg, &sig_check);
767+
if (ret)
755768
return ret;
756769
if (sig_check == msg->footer.sig)
757770
return 0;

0 commit comments

Comments
 (0)