gss_krb5_wrap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * COPYRIGHT (c) 2008
  3. * The Regents of the University of Michigan
  4. * ALL RIGHTS RESERVED
  5. *
  6. * Permission is granted to use, copy, create derivative works
  7. * and redistribute this software and such derivative works
  8. * for any purpose, so long as the name of The University of
  9. * Michigan is not used in any advertising or publicity
  10. * pertaining to the use of distribution of this software
  11. * without specific, written prior authorization. If the
  12. * above copyright notice or any other identification of the
  13. * University of Michigan is included in any copy of any
  14. * portion of this software, then the disclaimer below must
  15. * also be included.
  16. *
  17. * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
  18. * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
  19. * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
  20. * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
  21. * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
  23. * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
  25. * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
  26. * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
  27. * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGES.
  29. */
  30. #include <linux/types.h>
  31. #include <linux/jiffies.h>
  32. #include <linux/sunrpc/gss_krb5.h>
  33. #include <linux/random.h>
  34. #include <linux/pagemap.h>
  35. #include <linux/crypto.h>
  36. #ifdef RPC_DEBUG
  37. # define RPCDBG_FACILITY RPCDBG_AUTH
  38. #endif
  39. static inline int
  40. gss_krb5_padding(int blocksize, int length)
  41. {
  42. return blocksize - (length % blocksize);
  43. }
  44. static inline void
  45. gss_krb5_add_padding(struct xdr_buf *buf, int offset, int blocksize)
  46. {
  47. int padding = gss_krb5_padding(blocksize, buf->len - offset);
  48. char *p;
  49. struct kvec *iov;
  50. if (buf->page_len || buf->tail[0].iov_len)
  51. iov = &buf->tail[0];
  52. else
  53. iov = &buf->head[0];
  54. p = iov->iov_base + iov->iov_len;
  55. iov->iov_len += padding;
  56. buf->len += padding;
  57. memset(p, padding, padding);
  58. }
  59. static inline int
  60. gss_krb5_remove_padding(struct xdr_buf *buf, int blocksize)
  61. {
  62. u8 *ptr;
  63. u8 pad;
  64. size_t len = buf->len;
  65. if (len <= buf->head[0].iov_len) {
  66. pad = *(u8 *)(buf->head[0].iov_base + len - 1);
  67. if (pad > buf->head[0].iov_len)
  68. return -EINVAL;
  69. buf->head[0].iov_len -= pad;
  70. goto out;
  71. } else
  72. len -= buf->head[0].iov_len;
  73. if (len <= buf->page_len) {
  74. unsigned int last = (buf->page_base + len - 1)
  75. >>PAGE_CACHE_SHIFT;
  76. unsigned int offset = (buf->page_base + len - 1)
  77. & (PAGE_CACHE_SIZE - 1);
  78. ptr = kmap_atomic(buf->pages[last], KM_USER0);
  79. pad = *(ptr + offset);
  80. kunmap_atomic(ptr, KM_USER0);
  81. goto out;
  82. } else
  83. len -= buf->page_len;
  84. BUG_ON(len > buf->tail[0].iov_len);
  85. pad = *(u8 *)(buf->tail[0].iov_base + len - 1);
  86. out:
  87. /* XXX: NOTE: we do not adjust the page lengths--they represent
  88. * a range of data in the real filesystem page cache, and we need
  89. * to know that range so the xdr code can properly place read data.
  90. * However adjusting the head length, as we do above, is harmless.
  91. * In the case of a request that fits into a single page, the server
  92. * also uses length and head length together to determine the original
  93. * start of the request to copy the request for deferal; so it's
  94. * easier on the server if we adjust head and tail length in tandem.
  95. * It's not really a problem that we don't fool with the page and
  96. * tail lengths, though--at worst badly formed xdr might lead the
  97. * server to attempt to parse the padding.
  98. * XXX: Document all these weird requirements for gss mechanism
  99. * wrap/unwrap functions. */
  100. if (pad > blocksize)
  101. return -EINVAL;
  102. if (buf->len > pad)
  103. buf->len -= pad;
  104. else
  105. return -EINVAL;
  106. return 0;
  107. }
  108. void
  109. gss_krb5_make_confounder(char *p, u32 conflen)
  110. {
  111. static u64 i = 0;
  112. u64 *q = (u64 *)p;
  113. /* rfc1964 claims this should be "random". But all that's really
  114. * necessary is that it be unique. And not even that is necessary in
  115. * our case since our "gssapi" implementation exists only to support
  116. * rpcsec_gss, so we know that the only buffers we will ever encrypt
  117. * already begin with a unique sequence number. Just to hedge my bets
  118. * I'll make a half-hearted attempt at something unique, but ensuring
  119. * uniqueness would mean worrying about atomicity and rollover, and I
  120. * don't care enough. */
  121. /* initialize to random value */
  122. if (i == 0) {
  123. i = random32();
  124. i = (i << 32) | random32();
  125. }
  126. switch (conflen) {
  127. case 16:
  128. *q++ = i++;
  129. /* fall through */
  130. case 8:
  131. *q++ = i++;
  132. break;
  133. default:
  134. BUG();
  135. }
  136. }
  137. /* Assumptions: the head and tail of inbuf are ours to play with.
  138. * The pages, however, may be real pages in the page cache and we replace
  139. * them with scratch pages from **pages before writing to them. */
  140. /* XXX: obviously the above should be documentation of wrap interface,
  141. * and shouldn't be in this kerberos-specific file. */
  142. /* XXX factor out common code with seal/unseal. */
  143. static u32
  144. gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,
  145. struct xdr_buf *buf, struct page **pages)
  146. {
  147. char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
  148. struct xdr_netobj md5cksum = {.len = sizeof(cksumdata),
  149. .data = cksumdata};
  150. int blocksize = 0, plainlen;
  151. unsigned char *ptr, *msg_start;
  152. s32 now;
  153. int headlen;
  154. struct page **tmp_pages;
  155. u32 seq_send;
  156. u8 *cksumkey;
  157. u32 conflen = kctx->gk5e->conflen;
  158. dprintk("RPC: %s\n", __func__);
  159. now = get_seconds();
  160. blocksize = crypto_blkcipher_blocksize(kctx->enc);
  161. gss_krb5_add_padding(buf, offset, blocksize);
  162. BUG_ON((buf->len - offset) % blocksize);
  163. plainlen = conflen + buf->len - offset;
  164. headlen = g_token_size(&kctx->mech_used,
  165. GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength + plainlen) -
  166. (buf->len - offset);
  167. ptr = buf->head[0].iov_base + offset;
  168. /* shift data to make room for header. */
  169. xdr_extend_head(buf, offset, headlen);
  170. /* XXX Would be cleverer to encrypt while copying. */
  171. BUG_ON((buf->len - offset - headlen) % blocksize);
  172. g_make_token_header(&kctx->mech_used,
  173. GSS_KRB5_TOK_HDR_LEN +
  174. kctx->gk5e->cksumlength + plainlen, &ptr);
  175. /* ptr now at header described in rfc 1964, section 1.2.1: */
  176. ptr[0] = (unsigned char) ((KG_TOK_WRAP_MSG >> 8) & 0xff);
  177. ptr[1] = (unsigned char) (KG_TOK_WRAP_MSG & 0xff);
  178. msg_start = ptr + GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength;
  179. *(__be16 *)(ptr + 2) = cpu_to_le16(kctx->gk5e->signalg);
  180. memset(ptr + 4, 0xff, 4);
  181. *(__be16 *)(ptr + 4) = cpu_to_le16(kctx->gk5e->sealalg);
  182. gss_krb5_make_confounder(msg_start, conflen);
  183. if (kctx->gk5e->keyed_cksum)
  184. cksumkey = kctx->cksum;
  185. else
  186. cksumkey = NULL;
  187. /* XXXJBF: UGH!: */
  188. tmp_pages = buf->pages;
  189. buf->pages = pages;
  190. if (make_checksum(kctx, ptr, 8, buf, offset + headlen - conflen,
  191. cksumkey, KG_USAGE_SEAL, &md5cksum))
  192. return GSS_S_FAILURE;
  193. buf->pages = tmp_pages;
  194. memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data, md5cksum.len);
  195. spin_lock(&krb5_seq_lock);
  196. seq_send = kctx->seq_send++;
  197. spin_unlock(&krb5_seq_lock);
  198. /* XXX would probably be more efficient to compute checksum
  199. * and encrypt at the same time: */
  200. if ((krb5_make_seq_num(kctx, kctx->seq, kctx->initiate ? 0 : 0xff,
  201. seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8)))
  202. return GSS_S_FAILURE;
  203. if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC) {
  204. struct crypto_blkcipher *cipher;
  205. int err;
  206. cipher = crypto_alloc_blkcipher(kctx->gk5e->encrypt_name, 0,
  207. CRYPTO_ALG_ASYNC);
  208. if (IS_ERR(cipher))
  209. return GSS_S_FAILURE;
  210. krb5_rc4_setup_enc_key(kctx, cipher, seq_send);
  211. err = gss_encrypt_xdr_buf(cipher, buf,
  212. offset + headlen - conflen, pages);
  213. crypto_free_blkcipher(cipher);
  214. if (err)
  215. return GSS_S_FAILURE;
  216. } else {
  217. if (gss_encrypt_xdr_buf(kctx->enc, buf,
  218. offset + headlen - conflen, pages))
  219. return GSS_S_FAILURE;
  220. }
  221. return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
  222. }
  223. static u32
  224. gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
  225. {
  226. int signalg;
  227. int sealalg;
  228. char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
  229. struct xdr_netobj md5cksum = {.len = sizeof(cksumdata),
  230. .data = cksumdata};
  231. s32 now;
  232. int direction;
  233. s32 seqnum;
  234. unsigned char *ptr;
  235. int bodysize;
  236. void *data_start, *orig_start;
  237. int data_len;
  238. int blocksize;
  239. u32 conflen = kctx->gk5e->conflen;
  240. int crypt_offset;
  241. u8 *cksumkey;
  242. dprintk("RPC: gss_unwrap_kerberos\n");
  243. ptr = (u8 *)buf->head[0].iov_base + offset;
  244. if (g_verify_token_header(&kctx->mech_used, &bodysize, &ptr,
  245. buf->len - offset))
  246. return GSS_S_DEFECTIVE_TOKEN;
  247. if ((ptr[0] != ((KG_TOK_WRAP_MSG >> 8) & 0xff)) ||
  248. (ptr[1] != (KG_TOK_WRAP_MSG & 0xff)))
  249. return GSS_S_DEFECTIVE_TOKEN;
  250. /* XXX sanity-check bodysize?? */
  251. /* get the sign and seal algorithms */
  252. signalg = ptr[2] + (ptr[3] << 8);
  253. if (signalg != kctx->gk5e->signalg)
  254. return GSS_S_DEFECTIVE_TOKEN;
  255. sealalg = ptr[4] + (ptr[5] << 8);
  256. if (sealalg != kctx->gk5e->sealalg)
  257. return GSS_S_DEFECTIVE_TOKEN;
  258. if ((ptr[6] != 0xff) || (ptr[7] != 0xff))
  259. return GSS_S_DEFECTIVE_TOKEN;
  260. /*
  261. * Data starts after token header and checksum. ptr points
  262. * to the beginning of the token header
  263. */
  264. crypt_offset = ptr + (GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength) -
  265. (unsigned char *)buf->head[0].iov_base;
  266. /*
  267. * Need plaintext seqnum to derive encryption key for arcfour-hmac
  268. */
  269. if (krb5_get_seq_num(kctx, ptr + GSS_KRB5_TOK_HDR_LEN,
  270. ptr + 8, &direction, &seqnum))
  271. return GSS_S_BAD_SIG;
  272. if ((kctx->initiate && direction != 0xff) ||
  273. (!kctx->initiate && direction != 0))
  274. return GSS_S_BAD_SIG;
  275. if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC) {
  276. struct crypto_blkcipher *cipher;
  277. int err;
  278. cipher = crypto_alloc_blkcipher(kctx->gk5e->encrypt_name, 0,
  279. CRYPTO_ALG_ASYNC);
  280. if (IS_ERR(cipher))
  281. return GSS_S_FAILURE;
  282. krb5_rc4_setup_enc_key(kctx, cipher, seqnum);
  283. err = gss_decrypt_xdr_buf(cipher, buf, crypt_offset);
  284. crypto_free_blkcipher(cipher);
  285. if (err)
  286. return GSS_S_DEFECTIVE_TOKEN;
  287. } else {
  288. if (gss_decrypt_xdr_buf(kctx->enc, buf, crypt_offset))
  289. return GSS_S_DEFECTIVE_TOKEN;
  290. }
  291. if (kctx->gk5e->keyed_cksum)
  292. cksumkey = kctx->cksum;
  293. else
  294. cksumkey = NULL;
  295. if (make_checksum(kctx, ptr, 8, buf, crypt_offset,
  296. cksumkey, KG_USAGE_SEAL, &md5cksum))
  297. return GSS_S_FAILURE;
  298. if (memcmp(md5cksum.data, ptr + GSS_KRB5_TOK_HDR_LEN,
  299. kctx->gk5e->cksumlength))
  300. return GSS_S_BAD_SIG;
  301. /* it got through unscathed. Make sure the context is unexpired */
  302. now = get_seconds();
  303. if (now > kctx->endtime)
  304. return GSS_S_CONTEXT_EXPIRED;
  305. /* do sequencing checks */
  306. /* Copy the data back to the right position. XXX: Would probably be
  307. * better to copy and encrypt at the same time. */
  308. blocksize = crypto_blkcipher_blocksize(kctx->enc);
  309. data_start = ptr + (GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength) +
  310. conflen;
  311. orig_start = buf->head[0].iov_base + offset;
  312. data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start;
  313. memmove(orig_start, data_start, data_len);
  314. buf->head[0].iov_len -= (data_start - orig_start);
  315. buf->len -= (data_start - orig_start);
  316. if (gss_krb5_remove_padding(buf, blocksize))
  317. return GSS_S_DEFECTIVE_TOKEN;
  318. return GSS_S_COMPLETE;
  319. }
  320. /*
  321. * We cannot currently handle tokens with rotated data. We need a
  322. * generalized routine to rotate the data in place. It is anticipated
  323. * that we won't encounter rotated data in the general case.
  324. */
  325. static u32
  326. rotate_left(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf, u16 rrc)
  327. {
  328. unsigned int realrrc = rrc % (buf->len - offset - GSS_KRB5_TOK_HDR_LEN);
  329. if (realrrc == 0)
  330. return 0;
  331. dprintk("%s: cannot process token with rotated data: "
  332. "rrc %u, realrrc %u\n", __func__, rrc, realrrc);
  333. return 1;
  334. }
  335. static u32
  336. gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
  337. struct xdr_buf *buf, struct page **pages)
  338. {
  339. int blocksize;
  340. u8 *ptr, *plainhdr;
  341. s32 now;
  342. u8 flags = 0x00;
  343. __be16 *be16ptr, ec = 0;
  344. __be64 *be64ptr;
  345. u32 err;
  346. dprintk("RPC: %s\n", __func__);
  347. if (kctx->gk5e->encrypt_v2 == NULL)
  348. return GSS_S_FAILURE;
  349. /* make room for gss token header */
  350. if (xdr_extend_head(buf, offset, GSS_KRB5_TOK_HDR_LEN))
  351. return GSS_S_FAILURE;
  352. /* construct gss token header */
  353. ptr = plainhdr = buf->head[0].iov_base + offset;
  354. *ptr++ = (unsigned char) ((KG2_TOK_WRAP>>8) & 0xff);
  355. *ptr++ = (unsigned char) (KG2_TOK_WRAP & 0xff);
  356. if ((kctx->flags & KRB5_CTX_FLAG_INITIATOR) == 0)
  357. flags |= KG2_TOKEN_FLAG_SENTBYACCEPTOR;
  358. if ((kctx->flags & KRB5_CTX_FLAG_ACCEPTOR_SUBKEY) != 0)
  359. flags |= KG2_TOKEN_FLAG_ACCEPTORSUBKEY;
  360. /* We always do confidentiality in wrap tokens */
  361. flags |= KG2_TOKEN_FLAG_SEALED;
  362. *ptr++ = flags;
  363. *ptr++ = 0xff;
  364. be16ptr = (__be16 *)ptr;
  365. blocksize = crypto_blkcipher_blocksize(kctx->acceptor_enc);
  366. *be16ptr++ = cpu_to_be16(ec);
  367. /* "inner" token header always uses 0 for RRC */
  368. *be16ptr++ = cpu_to_be16(0);
  369. be64ptr = (__be64 *)be16ptr;
  370. spin_lock(&krb5_seq_lock);
  371. *be64ptr = cpu_to_be64(kctx->seq_send64++);
  372. spin_unlock(&krb5_seq_lock);
  373. err = (*kctx->gk5e->encrypt_v2)(kctx, offset, buf, ec, pages);
  374. if (err)
  375. return err;
  376. now = get_seconds();
  377. return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
  378. }
  379. static u32
  380. gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
  381. {
  382. s32 now;
  383. u64 seqnum;
  384. u8 *ptr;
  385. u8 flags = 0x00;
  386. u16 ec, rrc;
  387. int err;
  388. u32 headskip, tailskip;
  389. u8 decrypted_hdr[GSS_KRB5_TOK_HDR_LEN];
  390. unsigned int movelen;
  391. dprintk("RPC: %s\n", __func__);
  392. if (kctx->gk5e->decrypt_v2 == NULL)
  393. return GSS_S_FAILURE;
  394. ptr = buf->head[0].iov_base + offset;
  395. if (be16_to_cpu(*((__be16 *)ptr)) != KG2_TOK_WRAP)
  396. return GSS_S_DEFECTIVE_TOKEN;
  397. flags = ptr[2];
  398. if ((!kctx->initiate && (flags & KG2_TOKEN_FLAG_SENTBYACCEPTOR)) ||
  399. (kctx->initiate && !(flags & KG2_TOKEN_FLAG_SENTBYACCEPTOR)))
  400. return GSS_S_BAD_SIG;
  401. if ((flags & KG2_TOKEN_FLAG_SEALED) == 0) {
  402. dprintk("%s: token missing expected sealed flag\n", __func__);
  403. return GSS_S_DEFECTIVE_TOKEN;
  404. }
  405. if (ptr[3] != 0xff)
  406. return GSS_S_DEFECTIVE_TOKEN;
  407. ec = be16_to_cpup((__be16 *)(ptr + 4));
  408. rrc = be16_to_cpup((__be16 *)(ptr + 6));
  409. seqnum = be64_to_cpup((__be64 *)(ptr + 8));
  410. if (rrc != 0) {
  411. err = rotate_left(kctx, offset, buf, rrc);
  412. if (err)
  413. return GSS_S_FAILURE;
  414. }
  415. err = (*kctx->gk5e->decrypt_v2)(kctx, offset, buf,
  416. &headskip, &tailskip);
  417. if (err)
  418. return GSS_S_FAILURE;
  419. /*
  420. * Retrieve the decrypted gss token header and verify
  421. * it against the original
  422. */
  423. err = read_bytes_from_xdr_buf(buf,
  424. buf->len - GSS_KRB5_TOK_HDR_LEN - tailskip,
  425. decrypted_hdr, GSS_KRB5_TOK_HDR_LEN);
  426. if (err) {
  427. dprintk("%s: error %u getting decrypted_hdr\n", __func__, err);
  428. return GSS_S_FAILURE;
  429. }
  430. if (memcmp(ptr, decrypted_hdr, 6)
  431. || memcmp(ptr + 8, decrypted_hdr + 8, 8)) {
  432. dprintk("%s: token hdr, plaintext hdr mismatch!\n", __func__);
  433. return GSS_S_FAILURE;
  434. }
  435. /* do sequencing checks */
  436. /* it got through unscathed. Make sure the context is unexpired */
  437. now = get_seconds();
  438. if (now > kctx->endtime)
  439. return GSS_S_CONTEXT_EXPIRED;
  440. /*
  441. * Move the head data back to the right position in xdr_buf.
  442. * We ignore any "ec" data since it might be in the head or
  443. * the tail, and we really don't need to deal with it.
  444. * Note that buf->head[0].iov_len may indicate the available
  445. * head buffer space rather than that actually occupied.
  446. */
  447. movelen = min_t(unsigned int, buf->head[0].iov_len, buf->len);
  448. movelen -= offset + GSS_KRB5_TOK_HDR_LEN + headskip;
  449. BUG_ON(offset + GSS_KRB5_TOK_HDR_LEN + headskip + movelen >
  450. buf->head[0].iov_len);
  451. memmove(ptr, ptr + GSS_KRB5_TOK_HDR_LEN + headskip, movelen);
  452. buf->head[0].iov_len -= GSS_KRB5_TOK_HDR_LEN + headskip;
  453. buf->len -= GSS_KRB5_TOK_HDR_LEN + headskip;
  454. return GSS_S_COMPLETE;
  455. }
  456. u32
  457. gss_wrap_kerberos(struct gss_ctx *gctx, int offset,
  458. struct xdr_buf *buf, struct page **pages)
  459. {
  460. struct krb5_ctx *kctx = gctx->internal_ctx_id;
  461. switch (kctx->enctype) {
  462. default:
  463. BUG();
  464. case ENCTYPE_DES_CBC_RAW:
  465. case ENCTYPE_DES3_CBC_RAW:
  466. case ENCTYPE_ARCFOUR_HMAC:
  467. return gss_wrap_kerberos_v1(kctx, offset, buf, pages);
  468. case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
  469. case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
  470. return gss_wrap_kerberos_v2(kctx, offset, buf, pages);
  471. }
  472. }
  473. u32
  474. gss_unwrap_kerberos(struct gss_ctx *gctx, int offset, struct xdr_buf *buf)
  475. {
  476. struct krb5_ctx *kctx = gctx->internal_ctx_id;
  477. switch (kctx->enctype) {
  478. default:
  479. BUG();
  480. case ENCTYPE_DES_CBC_RAW:
  481. case ENCTYPE_DES3_CBC_RAW:
  482. case ENCTYPE_ARCFOUR_HMAC:
  483. return gss_unwrap_kerberos_v1(kctx, offset, buf);
  484. case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
  485. case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
  486. return gss_unwrap_kerberos_v2(kctx, offset, buf);
  487. }
  488. }