J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 1 | #include <linux/types.h> |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 2 | #include <linux/jiffies.h> |
| 3 | #include <linux/sunrpc/gss_krb5.h> |
| 4 | #include <linux/random.h> |
| 5 | #include <linux/pagemap.h> |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 6 | #include <linux/crypto.h> |
| 7 | |
| 8 | #ifdef RPC_DEBUG |
| 9 | # define RPCDBG_FACILITY RPCDBG_AUTH |
| 10 | #endif |
| 11 | |
| 12 | static inline int |
| 13 | gss_krb5_padding(int blocksize, int length) |
| 14 | { |
| 15 | /* Most of the code is block-size independent but currently we |
| 16 | * use only 8: */ |
| 17 | BUG_ON(blocksize != 8); |
| 18 | return 8 - (length & 7); |
| 19 | } |
| 20 | |
| 21 | static inline void |
| 22 | gss_krb5_add_padding(struct xdr_buf *buf, int offset, int blocksize) |
| 23 | { |
| 24 | int padding = gss_krb5_padding(blocksize, buf->len - offset); |
| 25 | char *p; |
| 26 | struct kvec *iov; |
| 27 | |
| 28 | if (buf->page_len || buf->tail[0].iov_len) |
| 29 | iov = &buf->tail[0]; |
| 30 | else |
| 31 | iov = &buf->head[0]; |
| 32 | p = iov->iov_base + iov->iov_len; |
| 33 | iov->iov_len += padding; |
| 34 | buf->len += padding; |
| 35 | memset(p, padding, padding); |
| 36 | } |
| 37 | |
| 38 | static inline int |
| 39 | gss_krb5_remove_padding(struct xdr_buf *buf, int blocksize) |
| 40 | { |
| 41 | u8 *ptr; |
| 42 | u8 pad; |
Chuck Lever | 67f97d8 | 2007-09-26 14:38:10 -0400 | [diff] [blame] | 43 | size_t len = buf->len; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 44 | |
| 45 | if (len <= buf->head[0].iov_len) { |
| 46 | pad = *(u8 *)(buf->head[0].iov_base + len - 1); |
| 47 | if (pad > buf->head[0].iov_len) |
| 48 | return -EINVAL; |
| 49 | buf->head[0].iov_len -= pad; |
| 50 | goto out; |
| 51 | } else |
| 52 | len -= buf->head[0].iov_len; |
| 53 | if (len <= buf->page_len) { |
Chuck Lever | 67f97d8 | 2007-09-26 14:38:10 -0400 | [diff] [blame] | 54 | unsigned int last = (buf->page_base + len - 1) |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 55 | >>PAGE_CACHE_SHIFT; |
Chuck Lever | 67f97d8 | 2007-09-26 14:38:10 -0400 | [diff] [blame] | 56 | unsigned int offset = (buf->page_base + len - 1) |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 57 | & (PAGE_CACHE_SIZE - 1); |
J. Bruce Fields | 87d918d | 2006-12-04 20:22:32 -0500 | [diff] [blame] | 58 | ptr = kmap_atomic(buf->pages[last], KM_USER0); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 59 | pad = *(ptr + offset); |
J. Bruce Fields | 87d918d | 2006-12-04 20:22:32 -0500 | [diff] [blame] | 60 | kunmap_atomic(ptr, KM_USER0); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 61 | goto out; |
| 62 | } else |
| 63 | len -= buf->page_len; |
| 64 | BUG_ON(len > buf->tail[0].iov_len); |
| 65 | pad = *(u8 *)(buf->tail[0].iov_base + len - 1); |
| 66 | out: |
| 67 | /* XXX: NOTE: we do not adjust the page lengths--they represent |
| 68 | * a range of data in the real filesystem page cache, and we need |
| 69 | * to know that range so the xdr code can properly place read data. |
| 70 | * However adjusting the head length, as we do above, is harmless. |
| 71 | * In the case of a request that fits into a single page, the server |
| 72 | * also uses length and head length together to determine the original |
| 73 | * start of the request to copy the request for deferal; so it's |
| 74 | * easier on the server if we adjust head and tail length in tandem. |
| 75 | * It's not really a problem that we don't fool with the page and |
| 76 | * tail lengths, though--at worst badly formed xdr might lead the |
| 77 | * server to attempt to parse the padding. |
| 78 | * XXX: Document all these weird requirements for gss mechanism |
| 79 | * wrap/unwrap functions. */ |
| 80 | if (pad > blocksize) |
| 81 | return -EINVAL; |
| 82 | if (buf->len > pad) |
| 83 | buf->len -= pad; |
| 84 | else |
| 85 | return -EINVAL; |
| 86 | return 0; |
| 87 | } |
| 88 | |
Kevin Coffman | 863a248 | 2008-04-30 12:46:08 -0400 | [diff] [blame] | 89 | static void |
| 90 | make_confounder(char *p, u32 conflen) |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 91 | { |
| 92 | static u64 i = 0; |
| 93 | u64 *q = (u64 *)p; |
| 94 | |
| 95 | /* rfc1964 claims this should be "random". But all that's really |
| 96 | * necessary is that it be unique. And not even that is necessary in |
| 97 | * our case since our "gssapi" implementation exists only to support |
| 98 | * rpcsec_gss, so we know that the only buffers we will ever encrypt |
| 99 | * already begin with a unique sequence number. Just to hedge my bets |
| 100 | * I'll make a half-hearted attempt at something unique, but ensuring |
| 101 | * uniqueness would mean worrying about atomicity and rollover, and I |
| 102 | * don't care enough. */ |
| 103 | |
Kevin Coffman | 863a248 | 2008-04-30 12:46:08 -0400 | [diff] [blame] | 104 | /* initialize to random value */ |
| 105 | if (i == 0) { |
| 106 | i = random32(); |
| 107 | i = (i << 32) | random32(); |
| 108 | } |
| 109 | |
| 110 | switch (conflen) { |
| 111 | case 16: |
| 112 | *q++ = i++; |
| 113 | /* fall through */ |
| 114 | case 8: |
| 115 | *q++ = i++; |
| 116 | break; |
| 117 | default: |
| 118 | BUG(); |
| 119 | } |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* Assumptions: the head and tail of inbuf are ours to play with. |
| 123 | * The pages, however, may be real pages in the page cache and we replace |
| 124 | * them with scratch pages from **pages before writing to them. */ |
| 125 | /* XXX: obviously the above should be documentation of wrap interface, |
| 126 | * and shouldn't be in this kerberos-specific file. */ |
| 127 | |
| 128 | /* XXX factor out common code with seal/unseal. */ |
| 129 | |
| 130 | u32 |
J. Bruce Fields | 00fd6e1 | 2005-10-13 16:55:18 -0400 | [diff] [blame] | 131 | gss_wrap_kerberos(struct gss_ctx *ctx, int offset, |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 132 | struct xdr_buf *buf, struct page **pages) |
| 133 | { |
| 134 | struct krb5_ctx *kctx = ctx->internal_ctx_id; |
J. Bruce Fields | 9e57b30 | 2006-03-20 23:23:11 -0500 | [diff] [blame] | 135 | char cksumdata[16]; |
| 136 | struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 137 | int blocksize = 0, plainlen; |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 138 | unsigned char *ptr, *msg_start; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 139 | s32 now; |
| 140 | int headlen; |
| 141 | struct page **tmp_pages; |
J. Bruce Fields | eaa82ed | 2006-03-20 23:24:04 -0500 | [diff] [blame] | 142 | u32 seq_send; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 143 | |
Chuck Lever | 8885cb3 | 2007-01-31 12:14:05 -0500 | [diff] [blame] | 144 | dprintk("RPC: gss_wrap_kerberos\n"); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 145 | |
| 146 | now = get_seconds(); |
| 147 | |
Herbert Xu | 378c669 | 2006-08-22 20:33:54 +1000 | [diff] [blame] | 148 | blocksize = crypto_blkcipher_blocksize(kctx->enc); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 149 | gss_krb5_add_padding(buf, offset, blocksize); |
| 150 | BUG_ON((buf->len - offset) % blocksize); |
| 151 | plainlen = blocksize + buf->len - offset; |
| 152 | |
Kevin Coffman | 4ab4b0b | 2008-03-31 10:31:44 -0400 | [diff] [blame] | 153 | headlen = g_token_size(&kctx->mech_used, 24 + plainlen) - |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 154 | (buf->len - offset); |
| 155 | |
| 156 | ptr = buf->head[0].iov_base + offset; |
| 157 | /* shift data to make room for header. */ |
| 158 | /* XXX Would be cleverer to encrypt while copying. */ |
| 159 | /* XXX bounds checking, slack, etc. */ |
| 160 | memmove(ptr + headlen, ptr, buf->head[0].iov_len - offset); |
| 161 | buf->head[0].iov_len += headlen; |
| 162 | buf->len += headlen; |
| 163 | BUG_ON((buf->len - offset - headlen) % blocksize); |
| 164 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 165 | g_make_token_header(&kctx->mech_used, |
| 166 | GSS_KRB5_TOK_HDR_LEN + 8 + plainlen, &ptr); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 167 | |
| 168 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 169 | /* ptr now at header described in rfc 1964, section 1.2.1: */ |
| 170 | ptr[0] = (unsigned char) ((KG_TOK_WRAP_MSG >> 8) & 0xff); |
| 171 | ptr[1] = (unsigned char) (KG_TOK_WRAP_MSG & 0xff); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 172 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 173 | msg_start = ptr + 24; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 174 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 175 | *(__be16 *)(ptr + 2) = htons(SGN_ALG_DES_MAC_MD5); |
| 176 | memset(ptr + 4, 0xff, 4); |
| 177 | *(__be16 *)(ptr + 4) = htons(SEAL_ALG_DES); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 178 | |
| 179 | make_confounder(msg_start, blocksize); |
| 180 | |
| 181 | /* XXXJBF: UGH!: */ |
| 182 | tmp_pages = buf->pages; |
| 183 | buf->pages = pages; |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 184 | if (make_checksum("md5", ptr, 8, buf, |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 185 | offset + headlen - blocksize, &md5cksum)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 186 | return GSS_S_FAILURE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 187 | buf->pages = tmp_pages; |
| 188 | |
J. Bruce Fields | e678e06 | 2006-12-04 20:22:35 -0500 | [diff] [blame] | 189 | if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, |
| 190 | md5cksum.data, md5cksum.len)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 191 | return GSS_S_FAILURE; |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 192 | memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data + md5cksum.len - 8, 8); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 193 | |
J. Bruce Fields | eaa82ed | 2006-03-20 23:24:04 -0500 | [diff] [blame] | 194 | spin_lock(&krb5_seq_lock); |
| 195 | seq_send = kctx->seq_send++; |
| 196 | spin_unlock(&krb5_seq_lock); |
| 197 | |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 198 | /* XXX would probably be more efficient to compute checksum |
| 199 | * and encrypt at the same time: */ |
| 200 | if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff, |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 201 | seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8))) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 202 | return GSS_S_FAILURE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 203 | |
| 204 | if (gss_encrypt_xdr_buf(kctx->enc, buf, offset + headlen - blocksize, |
| 205 | pages)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 206 | return GSS_S_FAILURE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 207 | |
J. Bruce Fields | 94efa93 | 2006-12-04 20:22:42 -0500 | [diff] [blame] | 208 | return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | u32 |
J. Bruce Fields | 00fd6e1 | 2005-10-13 16:55:18 -0400 | [diff] [blame] | 212 | gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf) |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 213 | { |
| 214 | struct krb5_ctx *kctx = ctx->internal_ctx_id; |
| 215 | int signalg; |
| 216 | int sealalg; |
J. Bruce Fields | 9e57b30 | 2006-03-20 23:23:11 -0500 | [diff] [blame] | 217 | char cksumdata[16]; |
| 218 | struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 219 | s32 now; |
| 220 | int direction; |
| 221 | s32 seqnum; |
| 222 | unsigned char *ptr; |
| 223 | int bodysize; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 224 | void *data_start, *orig_start; |
| 225 | int data_len; |
| 226 | int blocksize; |
| 227 | |
Chuck Lever | 8885cb3 | 2007-01-31 12:14:05 -0500 | [diff] [blame] | 228 | dprintk("RPC: gss_unwrap_kerberos\n"); |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 229 | |
| 230 | ptr = (u8 *)buf->head[0].iov_base + offset; |
| 231 | if (g_verify_token_header(&kctx->mech_used, &bodysize, &ptr, |
| 232 | buf->len - offset)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 233 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 234 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 235 | if ((ptr[0] != ((KG_TOK_WRAP_MSG >> 8) & 0xff)) || |
| 236 | (ptr[1] != (KG_TOK_WRAP_MSG & 0xff))) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 237 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 238 | |
| 239 | /* XXX sanity-check bodysize?? */ |
| 240 | |
| 241 | /* get the sign and seal algorithms */ |
| 242 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 243 | signalg = ptr[2] + (ptr[3] << 8); |
J. Bruce Fields | 94efa93 | 2006-12-04 20:22:42 -0500 | [diff] [blame] | 244 | if (signalg != SGN_ALG_DES_MAC_MD5) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 245 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 246 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 247 | sealalg = ptr[4] + (ptr[5] << 8); |
J. Bruce Fields | d922a84 | 2006-12-04 20:22:40 -0500 | [diff] [blame] | 248 | if (sealalg != SEAL_ALG_DES) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 249 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 94efa93 | 2006-12-04 20:22:42 -0500 | [diff] [blame] | 250 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 251 | if ((ptr[6] != 0xff) || (ptr[7] != 0xff)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 252 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 253 | |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 254 | if (gss_decrypt_xdr_buf(kctx->enc, buf, |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 255 | ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 256 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 257 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 258 | if (make_checksum("md5", ptr, 8, buf, |
| 259 | ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base, &md5cksum)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 260 | return GSS_S_FAILURE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 261 | |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 262 | if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, |
| 263 | md5cksum.data, md5cksum.len)) |
| 264 | return GSS_S_FAILURE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 265 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 266 | if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 267 | return GSS_S_BAD_SIG; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 268 | |
| 269 | /* it got through unscathed. Make sure the context is unexpired */ |
| 270 | |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 271 | now = get_seconds(); |
| 272 | |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 273 | if (now > kctx->endtime) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 274 | return GSS_S_CONTEXT_EXPIRED; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 275 | |
| 276 | /* do sequencing checks */ |
| 277 | |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 278 | if (krb5_get_seq_num(kctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8, |
| 279 | &direction, &seqnum)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 280 | return GSS_S_BAD_SIG; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 281 | |
| 282 | if ((kctx->initiate && direction != 0xff) || |
| 283 | (!kctx->initiate && direction != 0)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 284 | return GSS_S_BAD_SIG; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 285 | |
| 286 | /* Copy the data back to the right position. XXX: Would probably be |
| 287 | * better to copy and encrypt at the same time. */ |
| 288 | |
Herbert Xu | 378c669 | 2006-08-22 20:33:54 +1000 | [diff] [blame] | 289 | blocksize = crypto_blkcipher_blocksize(kctx->enc); |
Kevin Coffman | d00953a | 2008-04-30 12:45:53 -0400 | [diff] [blame] | 290 | data_start = ptr + GSS_KRB5_TOK_HDR_LEN + 8 + blocksize; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 291 | orig_start = buf->head[0].iov_base + offset; |
| 292 | data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start; |
| 293 | memmove(orig_start, data_start, data_len); |
| 294 | buf->head[0].iov_len -= (data_start - orig_start); |
| 295 | buf->len -= (data_start - orig_start); |
| 296 | |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 297 | if (gss_krb5_remove_padding(buf, blocksize)) |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 298 | return GSS_S_DEFECTIVE_TOKEN; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 299 | |
J. Bruce Fields | 39a21dd | 2006-12-04 20:22:39 -0500 | [diff] [blame] | 300 | return GSS_S_COMPLETE; |
J. Bruce Fields | 14ae162 | 2005-10-13 16:55:13 -0400 | [diff] [blame] | 301 | } |