Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 10008
b: refs/heads/master
c: f7b3af6
h: refs/heads/master
v: v3
  • Loading branch information
J. Bruce Fields authored and Trond Myklebust committed Oct 19, 2005
1 parent 214510a commit a6d9d6f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2d2da60c63b67174add32f06e8d54c3a0c5cd9cf
refs/heads/master: f7b3af64c653c73feb060a9f94f2df9ab4bba4c3
106 changes: 77 additions & 29 deletions trunk/net/sunrpc/auth_gss/gss_krb5_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,82 @@ buf_to_sg(struct scatterlist *sg, char *ptr, int len) {
sg->length = len;
}

static int
process_xdr_buf(struct xdr_buf *buf, int offset, int len,
int (*actor)(struct scatterlist *, void *), void *data)
{
int i, page_len, thislen, page_offset, ret = 0;
struct scatterlist sg[1];

if (offset >= buf->head[0].iov_len) {
offset -= buf->head[0].iov_len;
} else {
thislen = buf->head[0].iov_len - offset;
if (thislen > len)
thislen = len;
buf_to_sg(sg, buf->head[0].iov_base + offset, thislen);
ret = actor(sg, data);
if (ret)
goto out;
offset = 0;
len -= thislen;
}
if (len == 0)
goto out;

if (offset >= buf->page_len) {
offset -= buf->page_len;
} else {
page_len = buf->page_len - offset;
if (page_len > len)
page_len = len;
len -= page_len;
page_offset = (offset + buf->page_base) & (PAGE_CACHE_SIZE - 1);
i = (offset + buf->page_base) >> PAGE_CACHE_SHIFT;
thislen = PAGE_CACHE_SIZE - page_offset;
do {
if (thislen > page_len)
thislen = page_len;
sg->page = buf->pages[i];
sg->offset = page_offset;
sg->length = thislen;
ret = actor(sg, data);
if (ret)
goto out;
page_len -= thislen;
i++;
page_offset = 0;
thislen = PAGE_CACHE_SIZE;
} while (page_len != 0);
offset = 0;
}
if (len == 0)
goto out;

if (offset < buf->tail[0].iov_len) {
thislen = buf->tail[0].iov_len - offset;
if (thislen > len)
thislen = len;
buf_to_sg(sg, buf->tail[0].iov_base + offset, thislen);
ret = actor(sg, data);
len -= thislen;
}
if (len != 0)
ret = -EINVAL;
out:
return ret;
}

static int
checksummer(struct scatterlist *sg, void *data)
{
struct crypto_tfm *tfm = (struct crypto_tfm *)data;

crypto_digest_update(tfm, sg, 1);

return 0;
}

/* checksum the plaintext data and hdrlen bytes of the token header */
s32
make_checksum(s32 cksumtype, char *header, int hdrlen, struct xdr_buf *body,
Expand All @@ -148,8 +224,6 @@ make_checksum(s32 cksumtype, char *header, int hdrlen, struct xdr_buf *body,
struct crypto_tfm *tfm = NULL; /* XXX add to ctx? */
struct scatterlist sg[1];
u32 code = GSS_S_FAILURE;
int len, thislen, offset;
int i;

switch (cksumtype) {
case CKSUMTYPE_RSA_MD5:
Expand All @@ -169,33 +243,7 @@ make_checksum(s32 cksumtype, char *header, int hdrlen, struct xdr_buf *body,
crypto_digest_init(tfm);
buf_to_sg(sg, header, hdrlen);
crypto_digest_update(tfm, sg, 1);
if (body->head[0].iov_len) {
buf_to_sg(sg, body->head[0].iov_base, body->head[0].iov_len);
crypto_digest_update(tfm, sg, 1);
}

len = body->page_len;
if (len != 0) {
offset = body->page_base & (PAGE_CACHE_SIZE - 1);
i = body->page_base >> PAGE_CACHE_SHIFT;
thislen = PAGE_CACHE_SIZE - offset;
do {
if (thislen > len)
thislen = len;
sg->page = body->pages[i];
sg->offset = offset;
sg->length = thislen;
crypto_digest_update(tfm, sg, 1);
len -= thislen;
i++;
offset = 0;
thislen = PAGE_CACHE_SIZE;
} while(len != 0);
}
if (body->tail[0].iov_len) {
buf_to_sg(sg, body->tail[0].iov_base, body->tail[0].iov_len);
crypto_digest_update(tfm, sg, 1);
}
process_xdr_buf(body, 0, body->len, checksummer, tfm);
crypto_digest_final(tfm, cksum->data);
code = 0;
out:
Expand Down

0 comments on commit a6d9d6f

Please sign in to comment.