rxkad.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /* Kerberos-based RxRPC security
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <crypto/skcipher.h>
  13. #include <linux/module.h>
  14. #include <linux/net.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/udp.h>
  17. #include <linux/scatterlist.h>
  18. #include <linux/ctype.h>
  19. #include <linux/slab.h>
  20. #include <net/sock.h>
  21. #include <net/af_rxrpc.h>
  22. #include <keys/rxrpc-type.h>
  23. #include "ar-internal.h"
  24. #define RXKAD_VERSION 2
  25. #define MAXKRB5TICKETLEN 1024
  26. #define RXKAD_TKT_TYPE_KERBEROS_V5 256
  27. #define ANAME_SZ 40 /* size of authentication name */
  28. #define INST_SZ 40 /* size of principal's instance */
  29. #define REALM_SZ 40 /* size of principal's auth domain */
  30. #define SNAME_SZ 40 /* size of service name */
  31. struct rxkad_level1_hdr {
  32. __be32 data_size; /* true data size (excluding padding) */
  33. };
  34. struct rxkad_level2_hdr {
  35. __be32 data_size; /* true data size (excluding padding) */
  36. __be32 checksum; /* decrypted data checksum */
  37. };
  38. /*
  39. * this holds a pinned cipher so that keventd doesn't get called by the cipher
  40. * alloc routine, but since we have it to hand, we use it to decrypt RESPONSE
  41. * packets
  42. */
  43. static struct crypto_skcipher *rxkad_ci;
  44. static DEFINE_MUTEX(rxkad_ci_mutex);
  45. /*
  46. * initialise connection security
  47. */
  48. static int rxkad_init_connection_security(struct rxrpc_connection *conn)
  49. {
  50. struct crypto_skcipher *ci;
  51. struct rxrpc_key_token *token;
  52. int ret;
  53. _enter("{%d},{%x}", conn->debug_id, key_serial(conn->params.key));
  54. token = conn->params.key->payload.data[0];
  55. conn->security_ix = token->security_index;
  56. ci = crypto_alloc_skcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC);
  57. if (IS_ERR(ci)) {
  58. _debug("no cipher");
  59. ret = PTR_ERR(ci);
  60. goto error;
  61. }
  62. if (crypto_skcipher_setkey(ci, token->kad->session_key,
  63. sizeof(token->kad->session_key)) < 0)
  64. BUG();
  65. switch (conn->params.security_level) {
  66. case RXRPC_SECURITY_PLAIN:
  67. break;
  68. case RXRPC_SECURITY_AUTH:
  69. conn->size_align = 8;
  70. conn->security_size = sizeof(struct rxkad_level1_hdr);
  71. break;
  72. case RXRPC_SECURITY_ENCRYPT:
  73. conn->size_align = 8;
  74. conn->security_size = sizeof(struct rxkad_level2_hdr);
  75. break;
  76. default:
  77. ret = -EKEYREJECTED;
  78. goto error;
  79. }
  80. conn->cipher = ci;
  81. ret = 0;
  82. error:
  83. _leave(" = %d", ret);
  84. return ret;
  85. }
  86. /*
  87. * prime the encryption state with the invariant parts of a connection's
  88. * description
  89. */
  90. static int rxkad_prime_packet_security(struct rxrpc_connection *conn)
  91. {
  92. struct rxrpc_key_token *token;
  93. SKCIPHER_REQUEST_ON_STACK(req, conn->cipher);
  94. struct scatterlist sg;
  95. struct rxrpc_crypt iv;
  96. __be32 *tmpbuf;
  97. size_t tmpsize = 4 * sizeof(__be32);
  98. _enter("");
  99. if (!conn->params.key)
  100. return 0;
  101. tmpbuf = kmalloc(tmpsize, GFP_KERNEL);
  102. if (!tmpbuf)
  103. return -ENOMEM;
  104. token = conn->params.key->payload.data[0];
  105. memcpy(&iv, token->kad->session_key, sizeof(iv));
  106. tmpbuf[0] = htonl(conn->proto.epoch);
  107. tmpbuf[1] = htonl(conn->proto.cid);
  108. tmpbuf[2] = 0;
  109. tmpbuf[3] = htonl(conn->security_ix);
  110. sg_init_one(&sg, tmpbuf, tmpsize);
  111. skcipher_request_set_tfm(req, conn->cipher);
  112. skcipher_request_set_callback(req, 0, NULL, NULL);
  113. skcipher_request_set_crypt(req, &sg, &sg, tmpsize, iv.x);
  114. crypto_skcipher_encrypt(req);
  115. skcipher_request_zero(req);
  116. memcpy(&conn->csum_iv, tmpbuf + 2, sizeof(conn->csum_iv));
  117. kfree(tmpbuf);
  118. _leave(" = 0");
  119. return 0;
  120. }
  121. /*
  122. * partially encrypt a packet (level 1 security)
  123. */
  124. static int rxkad_secure_packet_auth(const struct rxrpc_call *call,
  125. struct sk_buff *skb,
  126. u32 data_size,
  127. void *sechdr)
  128. {
  129. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  130. SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
  131. struct rxkad_level1_hdr hdr;
  132. struct rxrpc_crypt iv;
  133. struct scatterlist sg;
  134. u16 check;
  135. _enter("");
  136. check = sp->hdr.seq ^ call->call_id;
  137. data_size |= (u32)check << 16;
  138. hdr.data_size = htonl(data_size);
  139. memcpy(sechdr, &hdr, sizeof(hdr));
  140. /* start the encryption afresh */
  141. memset(&iv, 0, sizeof(iv));
  142. sg_init_one(&sg, sechdr, 8);
  143. skcipher_request_set_tfm(req, call->conn->cipher);
  144. skcipher_request_set_callback(req, 0, NULL, NULL);
  145. skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
  146. crypto_skcipher_encrypt(req);
  147. skcipher_request_zero(req);
  148. _leave(" = 0");
  149. return 0;
  150. }
  151. /*
  152. * wholly encrypt a packet (level 2 security)
  153. */
  154. static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
  155. struct sk_buff *skb,
  156. u32 data_size,
  157. void *sechdr)
  158. {
  159. const struct rxrpc_key_token *token;
  160. struct rxkad_level2_hdr rxkhdr;
  161. struct rxrpc_skb_priv *sp;
  162. SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
  163. struct rxrpc_crypt iv;
  164. struct scatterlist sg[16];
  165. struct sk_buff *trailer;
  166. unsigned int len;
  167. u16 check;
  168. int nsg;
  169. int err;
  170. sp = rxrpc_skb(skb);
  171. _enter("");
  172. check = sp->hdr.seq ^ call->call_id;
  173. rxkhdr.data_size = htonl(data_size | (u32)check << 16);
  174. rxkhdr.checksum = 0;
  175. memcpy(sechdr, &rxkhdr, sizeof(rxkhdr));
  176. /* encrypt from the session key */
  177. token = call->conn->params.key->payload.data[0];
  178. memcpy(&iv, token->kad->session_key, sizeof(iv));
  179. sg_init_one(&sg[0], sechdr, sizeof(rxkhdr));
  180. skcipher_request_set_tfm(req, call->conn->cipher);
  181. skcipher_request_set_callback(req, 0, NULL, NULL);
  182. skcipher_request_set_crypt(req, &sg[0], &sg[0], sizeof(rxkhdr), iv.x);
  183. crypto_skcipher_encrypt(req);
  184. /* we want to encrypt the skbuff in-place */
  185. nsg = skb_cow_data(skb, 0, &trailer);
  186. err = -ENOMEM;
  187. if (nsg < 0 || nsg > 16)
  188. goto out;
  189. len = data_size + call->conn->size_align - 1;
  190. len &= ~(call->conn->size_align - 1);
  191. sg_init_table(sg, nsg);
  192. err = skb_to_sgvec(skb, sg, 0, len);
  193. if (unlikely(err < 0))
  194. goto out;
  195. skcipher_request_set_crypt(req, sg, sg, len, iv.x);
  196. crypto_skcipher_encrypt(req);
  197. _leave(" = 0");
  198. err = 0;
  199. out:
  200. skcipher_request_zero(req);
  201. return err;
  202. }
  203. /*
  204. * checksum an RxRPC packet header
  205. */
  206. static int rxkad_secure_packet(struct rxrpc_call *call,
  207. struct sk_buff *skb,
  208. size_t data_size,
  209. void *sechdr)
  210. {
  211. struct rxrpc_skb_priv *sp;
  212. SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
  213. struct rxrpc_crypt iv;
  214. struct scatterlist sg;
  215. u32 x, y;
  216. int ret;
  217. sp = rxrpc_skb(skb);
  218. _enter("{%d{%x}},{#%u},%zu,",
  219. call->debug_id, key_serial(call->conn->params.key),
  220. sp->hdr.seq, data_size);
  221. if (!call->conn->cipher)
  222. return 0;
  223. ret = key_validate(call->conn->params.key);
  224. if (ret < 0)
  225. return ret;
  226. /* continue encrypting from where we left off */
  227. memcpy(&iv, call->conn->csum_iv.x, sizeof(iv));
  228. /* calculate the security checksum */
  229. x = (call->cid & RXRPC_CHANNELMASK) << (32 - RXRPC_CIDSHIFT);
  230. x |= sp->hdr.seq & 0x3fffffff;
  231. call->crypto_buf[0] = htonl(call->call_id);
  232. call->crypto_buf[1] = htonl(x);
  233. sg_init_one(&sg, call->crypto_buf, 8);
  234. skcipher_request_set_tfm(req, call->conn->cipher);
  235. skcipher_request_set_callback(req, 0, NULL, NULL);
  236. skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
  237. crypto_skcipher_encrypt(req);
  238. skcipher_request_zero(req);
  239. y = ntohl(call->crypto_buf[1]);
  240. y = (y >> 16) & 0xffff;
  241. if (y == 0)
  242. y = 1; /* zero checksums are not permitted */
  243. sp->hdr.cksum = y;
  244. switch (call->conn->params.security_level) {
  245. case RXRPC_SECURITY_PLAIN:
  246. ret = 0;
  247. break;
  248. case RXRPC_SECURITY_AUTH:
  249. ret = rxkad_secure_packet_auth(call, skb, data_size, sechdr);
  250. break;
  251. case RXRPC_SECURITY_ENCRYPT:
  252. ret = rxkad_secure_packet_encrypt(call, skb, data_size,
  253. sechdr);
  254. break;
  255. default:
  256. ret = -EPERM;
  257. break;
  258. }
  259. _leave(" = %d [set %hx]", ret, y);
  260. return ret;
  261. }
  262. /*
  263. * decrypt partial encryption on a packet (level 1 security)
  264. */
  265. static int rxkad_verify_packet_1(struct rxrpc_call *call, struct sk_buff *skb,
  266. unsigned int offset, unsigned int len,
  267. rxrpc_seq_t seq)
  268. {
  269. struct rxkad_level1_hdr sechdr;
  270. SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
  271. struct rxrpc_crypt iv;
  272. struct scatterlist sg[16];
  273. struct sk_buff *trailer;
  274. bool aborted;
  275. u32 data_size, buf;
  276. u16 check;
  277. int nsg, ret;
  278. _enter("");
  279. if (len < 8) {
  280. aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_hdr", "V1H",
  281. RXKADSEALEDINCON);
  282. goto protocol_error;
  283. }
  284. /* Decrypt the skbuff in-place. TODO: We really want to decrypt
  285. * directly into the target buffer.
  286. */
  287. nsg = skb_cow_data(skb, 0, &trailer);
  288. if (nsg < 0 || nsg > 16)
  289. goto nomem;
  290. sg_init_table(sg, nsg);
  291. ret = skb_to_sgvec(skb, sg, offset, 8);
  292. if (unlikely(ret < 0))
  293. return ret;
  294. /* start the decryption afresh */
  295. memset(&iv, 0, sizeof(iv));
  296. skcipher_request_set_tfm(req, call->conn->cipher);
  297. skcipher_request_set_callback(req, 0, NULL, NULL);
  298. skcipher_request_set_crypt(req, sg, sg, 8, iv.x);
  299. crypto_skcipher_decrypt(req);
  300. skcipher_request_zero(req);
  301. /* Extract the decrypted packet length */
  302. if (skb_copy_bits(skb, offset, &sechdr, sizeof(sechdr)) < 0) {
  303. aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_len", "XV1",
  304. RXKADDATALEN);
  305. goto protocol_error;
  306. }
  307. offset += sizeof(sechdr);
  308. len -= sizeof(sechdr);
  309. buf = ntohl(sechdr.data_size);
  310. data_size = buf & 0xffff;
  311. check = buf >> 16;
  312. check ^= seq ^ call->call_id;
  313. check &= 0xffff;
  314. if (check != 0) {
  315. aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_check", "V1C",
  316. RXKADSEALEDINCON);
  317. goto protocol_error;
  318. }
  319. if (data_size > len) {
  320. aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_datalen", "V1L",
  321. RXKADDATALEN);
  322. goto protocol_error;
  323. }
  324. _leave(" = 0 [dlen=%x]", data_size);
  325. return 0;
  326. protocol_error:
  327. if (aborted)
  328. rxrpc_send_abort_packet(call);
  329. return -EPROTO;
  330. nomem:
  331. _leave(" = -ENOMEM");
  332. return -ENOMEM;
  333. }
  334. /*
  335. * wholly decrypt a packet (level 2 security)
  336. */
  337. static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb,
  338. unsigned int offset, unsigned int len,
  339. rxrpc_seq_t seq)
  340. {
  341. const struct rxrpc_key_token *token;
  342. struct rxkad_level2_hdr sechdr;
  343. SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
  344. struct rxrpc_crypt iv;
  345. struct scatterlist _sg[4], *sg;
  346. struct sk_buff *trailer;
  347. bool aborted;
  348. u32 data_size, buf;
  349. u16 check;
  350. int nsg, ret;
  351. _enter(",{%d}", skb->len);
  352. if (len < 8) {
  353. aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_hdr", "V2H",
  354. RXKADSEALEDINCON);
  355. goto protocol_error;
  356. }
  357. /* Decrypt the skbuff in-place. TODO: We really want to decrypt
  358. * directly into the target buffer.
  359. */
  360. nsg = skb_cow_data(skb, 0, &trailer);
  361. if (nsg < 0)
  362. goto nomem;
  363. sg = _sg;
  364. if (unlikely(nsg > 4)) {
  365. sg = kmalloc_array(nsg, sizeof(*sg), GFP_NOIO);
  366. if (!sg)
  367. goto nomem;
  368. }
  369. sg_init_table(sg, nsg);
  370. ret = skb_to_sgvec(skb, sg, offset, len);
  371. if (unlikely(ret < 0)) {
  372. if (sg != _sg)
  373. kfree(sg);
  374. return ret;
  375. }
  376. /* decrypt from the session key */
  377. token = call->conn->params.key->payload.data[0];
  378. memcpy(&iv, token->kad->session_key, sizeof(iv));
  379. skcipher_request_set_tfm(req, call->conn->cipher);
  380. skcipher_request_set_callback(req, 0, NULL, NULL);
  381. skcipher_request_set_crypt(req, sg, sg, len, iv.x);
  382. crypto_skcipher_decrypt(req);
  383. skcipher_request_zero(req);
  384. if (sg != _sg)
  385. kfree(sg);
  386. /* Extract the decrypted packet length */
  387. if (skb_copy_bits(skb, offset, &sechdr, sizeof(sechdr)) < 0) {
  388. aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_len", "XV2",
  389. RXKADDATALEN);
  390. goto protocol_error;
  391. }
  392. offset += sizeof(sechdr);
  393. len -= sizeof(sechdr);
  394. buf = ntohl(sechdr.data_size);
  395. data_size = buf & 0xffff;
  396. check = buf >> 16;
  397. check ^= seq ^ call->call_id;
  398. check &= 0xffff;
  399. if (check != 0) {
  400. aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_check", "V2C",
  401. RXKADSEALEDINCON);
  402. goto protocol_error;
  403. }
  404. if (data_size > len) {
  405. aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_datalen", "V2L",
  406. RXKADDATALEN);
  407. goto protocol_error;
  408. }
  409. _leave(" = 0 [dlen=%x]", data_size);
  410. return 0;
  411. protocol_error:
  412. if (aborted)
  413. rxrpc_send_abort_packet(call);
  414. return -EPROTO;
  415. nomem:
  416. _leave(" = -ENOMEM");
  417. return -ENOMEM;
  418. }
  419. /*
  420. * Verify the security on a received packet or subpacket (if part of a
  421. * jumbo packet).
  422. */
  423. static int rxkad_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
  424. unsigned int offset, unsigned int len,
  425. rxrpc_seq_t seq, u16 expected_cksum)
  426. {
  427. SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher);
  428. struct rxrpc_crypt iv;
  429. struct scatterlist sg;
  430. bool aborted;
  431. u16 cksum;
  432. u32 x, y;
  433. _enter("{%d{%x}},{#%u}",
  434. call->debug_id, key_serial(call->conn->params.key), seq);
  435. if (!call->conn->cipher)
  436. return 0;
  437. /* continue encrypting from where we left off */
  438. memcpy(&iv, call->conn->csum_iv.x, sizeof(iv));
  439. /* validate the security checksum */
  440. x = (call->cid & RXRPC_CHANNELMASK) << (32 - RXRPC_CIDSHIFT);
  441. x |= seq & 0x3fffffff;
  442. call->crypto_buf[0] = htonl(call->call_id);
  443. call->crypto_buf[1] = htonl(x);
  444. sg_init_one(&sg, call->crypto_buf, 8);
  445. skcipher_request_set_tfm(req, call->conn->cipher);
  446. skcipher_request_set_callback(req, 0, NULL, NULL);
  447. skcipher_request_set_crypt(req, &sg, &sg, 8, iv.x);
  448. crypto_skcipher_encrypt(req);
  449. skcipher_request_zero(req);
  450. y = ntohl(call->crypto_buf[1]);
  451. cksum = (y >> 16) & 0xffff;
  452. if (cksum == 0)
  453. cksum = 1; /* zero checksums are not permitted */
  454. if (cksum != expected_cksum) {
  455. aborted = rxrpc_abort_eproto(call, skb, "rxkad_csum", "VCK",
  456. RXKADSEALEDINCON);
  457. goto protocol_error;
  458. }
  459. switch (call->conn->params.security_level) {
  460. case RXRPC_SECURITY_PLAIN:
  461. return 0;
  462. case RXRPC_SECURITY_AUTH:
  463. return rxkad_verify_packet_1(call, skb, offset, len, seq);
  464. case RXRPC_SECURITY_ENCRYPT:
  465. return rxkad_verify_packet_2(call, skb, offset, len, seq);
  466. default:
  467. return -ENOANO;
  468. }
  469. protocol_error:
  470. if (aborted)
  471. rxrpc_send_abort_packet(call);
  472. return -EPROTO;
  473. }
  474. /*
  475. * Locate the data contained in a packet that was partially encrypted.
  476. */
  477. static void rxkad_locate_data_1(struct rxrpc_call *call, struct sk_buff *skb,
  478. unsigned int *_offset, unsigned int *_len)
  479. {
  480. struct rxkad_level1_hdr sechdr;
  481. if (skb_copy_bits(skb, *_offset, &sechdr, sizeof(sechdr)) < 0)
  482. BUG();
  483. *_offset += sizeof(sechdr);
  484. *_len = ntohl(sechdr.data_size) & 0xffff;
  485. }
  486. /*
  487. * Locate the data contained in a packet that was completely encrypted.
  488. */
  489. static void rxkad_locate_data_2(struct rxrpc_call *call, struct sk_buff *skb,
  490. unsigned int *_offset, unsigned int *_len)
  491. {
  492. struct rxkad_level2_hdr sechdr;
  493. if (skb_copy_bits(skb, *_offset, &sechdr, sizeof(sechdr)) < 0)
  494. BUG();
  495. *_offset += sizeof(sechdr);
  496. *_len = ntohl(sechdr.data_size) & 0xffff;
  497. }
  498. /*
  499. * Locate the data contained in an already decrypted packet.
  500. */
  501. static void rxkad_locate_data(struct rxrpc_call *call, struct sk_buff *skb,
  502. unsigned int *_offset, unsigned int *_len)
  503. {
  504. switch (call->conn->params.security_level) {
  505. case RXRPC_SECURITY_AUTH:
  506. rxkad_locate_data_1(call, skb, _offset, _len);
  507. return;
  508. case RXRPC_SECURITY_ENCRYPT:
  509. rxkad_locate_data_2(call, skb, _offset, _len);
  510. return;
  511. default:
  512. return;
  513. }
  514. }
  515. /*
  516. * issue a challenge
  517. */
  518. static int rxkad_issue_challenge(struct rxrpc_connection *conn)
  519. {
  520. struct rxkad_challenge challenge;
  521. struct rxrpc_wire_header whdr;
  522. struct msghdr msg;
  523. struct kvec iov[2];
  524. size_t len;
  525. u32 serial;
  526. int ret;
  527. _enter("{%d,%x}", conn->debug_id, key_serial(conn->params.key));
  528. ret = key_validate(conn->params.key);
  529. if (ret < 0)
  530. return ret;
  531. get_random_bytes(&conn->security_nonce, sizeof(conn->security_nonce));
  532. challenge.version = htonl(2);
  533. challenge.nonce = htonl(conn->security_nonce);
  534. challenge.min_level = htonl(0);
  535. challenge.__padding = 0;
  536. msg.msg_name = &conn->params.peer->srx.transport;
  537. msg.msg_namelen = conn->params.peer->srx.transport_len;
  538. msg.msg_control = NULL;
  539. msg.msg_controllen = 0;
  540. msg.msg_flags = 0;
  541. whdr.epoch = htonl(conn->proto.epoch);
  542. whdr.cid = htonl(conn->proto.cid);
  543. whdr.callNumber = 0;
  544. whdr.seq = 0;
  545. whdr.type = RXRPC_PACKET_TYPE_CHALLENGE;
  546. whdr.flags = conn->out_clientflag;
  547. whdr.userStatus = 0;
  548. whdr.securityIndex = conn->security_ix;
  549. whdr._rsvd = 0;
  550. whdr.serviceId = htons(conn->service_id);
  551. iov[0].iov_base = &whdr;
  552. iov[0].iov_len = sizeof(whdr);
  553. iov[1].iov_base = &challenge;
  554. iov[1].iov_len = sizeof(challenge);
  555. len = iov[0].iov_len + iov[1].iov_len;
  556. serial = atomic_inc_return(&conn->serial);
  557. whdr.serial = htonl(serial);
  558. _proto("Tx CHALLENGE %%%u", serial);
  559. ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
  560. if (ret < 0) {
  561. trace_rxrpc_tx_fail(conn->debug_id, serial, ret,
  562. rxrpc_tx_fail_conn_challenge);
  563. return -EAGAIN;
  564. }
  565. conn->params.peer->last_tx_at = ktime_get_real();
  566. _leave(" = 0");
  567. return 0;
  568. }
  569. /*
  570. * send a Kerberos security response
  571. */
  572. static int rxkad_send_response(struct rxrpc_connection *conn,
  573. struct rxrpc_host_header *hdr,
  574. struct rxkad_response *resp,
  575. const struct rxkad_key *s2)
  576. {
  577. struct rxrpc_wire_header whdr;
  578. struct msghdr msg;
  579. struct kvec iov[3];
  580. size_t len;
  581. u32 serial;
  582. int ret;
  583. _enter("");
  584. msg.msg_name = &conn->params.peer->srx.transport;
  585. msg.msg_namelen = conn->params.peer->srx.transport_len;
  586. msg.msg_control = NULL;
  587. msg.msg_controllen = 0;
  588. msg.msg_flags = 0;
  589. memset(&whdr, 0, sizeof(whdr));
  590. whdr.epoch = htonl(hdr->epoch);
  591. whdr.cid = htonl(hdr->cid);
  592. whdr.type = RXRPC_PACKET_TYPE_RESPONSE;
  593. whdr.flags = conn->out_clientflag;
  594. whdr.securityIndex = hdr->securityIndex;
  595. whdr.serviceId = htons(hdr->serviceId);
  596. iov[0].iov_base = &whdr;
  597. iov[0].iov_len = sizeof(whdr);
  598. iov[1].iov_base = resp;
  599. iov[1].iov_len = sizeof(*resp);
  600. iov[2].iov_base = (void *)s2->ticket;
  601. iov[2].iov_len = s2->ticket_len;
  602. len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
  603. serial = atomic_inc_return(&conn->serial);
  604. whdr.serial = htonl(serial);
  605. _proto("Tx RESPONSE %%%u", serial);
  606. ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 3, len);
  607. if (ret < 0) {
  608. trace_rxrpc_tx_fail(conn->debug_id, serial, ret,
  609. rxrpc_tx_fail_conn_response);
  610. return -EAGAIN;
  611. }
  612. conn->params.peer->last_tx_at = ktime_get_real();
  613. _leave(" = 0");
  614. return 0;
  615. }
  616. /*
  617. * calculate the response checksum
  618. */
  619. static void rxkad_calc_response_checksum(struct rxkad_response *response)
  620. {
  621. u32 csum = 1000003;
  622. int loop;
  623. u8 *p = (u8 *) response;
  624. for (loop = sizeof(*response); loop > 0; loop--)
  625. csum = csum * 0x10204081 + *p++;
  626. response->encrypted.checksum = htonl(csum);
  627. }
  628. /*
  629. * encrypt the response packet
  630. */
  631. static void rxkad_encrypt_response(struct rxrpc_connection *conn,
  632. struct rxkad_response *resp,
  633. const struct rxkad_key *s2)
  634. {
  635. SKCIPHER_REQUEST_ON_STACK(req, conn->cipher);
  636. struct rxrpc_crypt iv;
  637. struct scatterlist sg[1];
  638. /* continue encrypting from where we left off */
  639. memcpy(&iv, s2->session_key, sizeof(iv));
  640. sg_init_table(sg, 1);
  641. sg_set_buf(sg, &resp->encrypted, sizeof(resp->encrypted));
  642. skcipher_request_set_tfm(req, conn->cipher);
  643. skcipher_request_set_callback(req, 0, NULL, NULL);
  644. skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x);
  645. crypto_skcipher_encrypt(req);
  646. skcipher_request_zero(req);
  647. }
  648. /*
  649. * respond to a challenge packet
  650. */
  651. static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
  652. struct sk_buff *skb,
  653. u32 *_abort_code)
  654. {
  655. const struct rxrpc_key_token *token;
  656. struct rxkad_challenge challenge;
  657. struct rxkad_response *resp;
  658. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  659. const char *eproto;
  660. u32 version, nonce, min_level, abort_code;
  661. int ret;
  662. _enter("{%d,%x}", conn->debug_id, key_serial(conn->params.key));
  663. eproto = tracepoint_string("chall_no_key");
  664. abort_code = RX_PROTOCOL_ERROR;
  665. if (!conn->params.key)
  666. goto protocol_error;
  667. abort_code = RXKADEXPIRED;
  668. ret = key_validate(conn->params.key);
  669. if (ret < 0)
  670. goto other_error;
  671. eproto = tracepoint_string("chall_short");
  672. abort_code = RXKADPACKETSHORT;
  673. if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
  674. &challenge, sizeof(challenge)) < 0)
  675. goto protocol_error;
  676. version = ntohl(challenge.version);
  677. nonce = ntohl(challenge.nonce);
  678. min_level = ntohl(challenge.min_level);
  679. _proto("Rx CHALLENGE %%%u { v=%u n=%u ml=%u }",
  680. sp->hdr.serial, version, nonce, min_level);
  681. eproto = tracepoint_string("chall_ver");
  682. abort_code = RXKADINCONSISTENCY;
  683. if (version != RXKAD_VERSION)
  684. goto protocol_error;
  685. abort_code = RXKADLEVELFAIL;
  686. ret = -EACCES;
  687. if (conn->params.security_level < min_level)
  688. goto other_error;
  689. token = conn->params.key->payload.data[0];
  690. /* build the response packet */
  691. resp = kzalloc(sizeof(struct rxkad_response), GFP_NOFS);
  692. if (!resp)
  693. return -ENOMEM;
  694. resp->version = htonl(RXKAD_VERSION);
  695. resp->encrypted.epoch = htonl(conn->proto.epoch);
  696. resp->encrypted.cid = htonl(conn->proto.cid);
  697. resp->encrypted.securityIndex = htonl(conn->security_ix);
  698. resp->encrypted.inc_nonce = htonl(nonce + 1);
  699. resp->encrypted.level = htonl(conn->params.security_level);
  700. resp->kvno = htonl(token->kad->kvno);
  701. resp->ticket_len = htonl(token->kad->ticket_len);
  702. resp->encrypted.call_id[0] = htonl(conn->channels[0].call_counter);
  703. resp->encrypted.call_id[1] = htonl(conn->channels[1].call_counter);
  704. resp->encrypted.call_id[2] = htonl(conn->channels[2].call_counter);
  705. resp->encrypted.call_id[3] = htonl(conn->channels[3].call_counter);
  706. /* calculate the response checksum and then do the encryption */
  707. rxkad_calc_response_checksum(resp);
  708. rxkad_encrypt_response(conn, resp, token->kad);
  709. ret = rxkad_send_response(conn, &sp->hdr, resp, token->kad);
  710. kfree(resp);
  711. return ret;
  712. protocol_error:
  713. trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto);
  714. ret = -EPROTO;
  715. other_error:
  716. *_abort_code = abort_code;
  717. return ret;
  718. }
  719. /*
  720. * decrypt the kerberos IV ticket in the response
  721. */
  722. static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,
  723. struct sk_buff *skb,
  724. void *ticket, size_t ticket_len,
  725. struct rxrpc_crypt *_session_key,
  726. time64_t *_expiry,
  727. u32 *_abort_code)
  728. {
  729. struct skcipher_request *req;
  730. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  731. struct rxrpc_crypt iv, key;
  732. struct scatterlist sg[1];
  733. struct in_addr addr;
  734. unsigned int life;
  735. const char *eproto;
  736. time64_t issue, now;
  737. bool little_endian;
  738. int ret;
  739. u32 abort_code;
  740. u8 *p, *q, *name, *end;
  741. _enter("{%d},{%x}", conn->debug_id, key_serial(conn->server_key));
  742. *_expiry = 0;
  743. ret = key_validate(conn->server_key);
  744. if (ret < 0) {
  745. switch (ret) {
  746. case -EKEYEXPIRED:
  747. abort_code = RXKADEXPIRED;
  748. goto other_error;
  749. default:
  750. abort_code = RXKADNOAUTH;
  751. goto other_error;
  752. }
  753. }
  754. ASSERT(conn->server_key->payload.data[0] != NULL);
  755. ASSERTCMP((unsigned long) ticket & 7UL, ==, 0);
  756. memcpy(&iv, &conn->server_key->payload.data[2], sizeof(iv));
  757. ret = -ENOMEM;
  758. req = skcipher_request_alloc(conn->server_key->payload.data[0],
  759. GFP_NOFS);
  760. if (!req)
  761. goto temporary_error;
  762. sg_init_one(&sg[0], ticket, ticket_len);
  763. skcipher_request_set_callback(req, 0, NULL, NULL);
  764. skcipher_request_set_crypt(req, sg, sg, ticket_len, iv.x);
  765. crypto_skcipher_decrypt(req);
  766. skcipher_request_free(req);
  767. p = ticket;
  768. end = p + ticket_len;
  769. #define Z(field) \
  770. ({ \
  771. u8 *__str = p; \
  772. eproto = tracepoint_string("rxkad_bad_"#field); \
  773. q = memchr(p, 0, end - p); \
  774. if (!q || q - p > (field##_SZ)) \
  775. goto bad_ticket; \
  776. for (; p < q; p++) \
  777. if (!isprint(*p)) \
  778. goto bad_ticket; \
  779. p++; \
  780. __str; \
  781. })
  782. /* extract the ticket flags */
  783. _debug("KIV FLAGS: %x", *p);
  784. little_endian = *p & 1;
  785. p++;
  786. /* extract the authentication name */
  787. name = Z(ANAME);
  788. _debug("KIV ANAME: %s", name);
  789. /* extract the principal's instance */
  790. name = Z(INST);
  791. _debug("KIV INST : %s", name);
  792. /* extract the principal's authentication domain */
  793. name = Z(REALM);
  794. _debug("KIV REALM: %s", name);
  795. eproto = tracepoint_string("rxkad_bad_len");
  796. if (end - p < 4 + 8 + 4 + 2)
  797. goto bad_ticket;
  798. /* get the IPv4 address of the entity that requested the ticket */
  799. memcpy(&addr, p, sizeof(addr));
  800. p += 4;
  801. _debug("KIV ADDR : %pI4", &addr);
  802. /* get the session key from the ticket */
  803. memcpy(&key, p, sizeof(key));
  804. p += 8;
  805. _debug("KIV KEY : %08x %08x", ntohl(key.n[0]), ntohl(key.n[1]));
  806. memcpy(_session_key, &key, sizeof(key));
  807. /* get the ticket's lifetime */
  808. life = *p++ * 5 * 60;
  809. _debug("KIV LIFE : %u", life);
  810. /* get the issue time of the ticket */
  811. if (little_endian) {
  812. __le32 stamp;
  813. memcpy(&stamp, p, 4);
  814. issue = rxrpc_u32_to_time64(le32_to_cpu(stamp));
  815. } else {
  816. __be32 stamp;
  817. memcpy(&stamp, p, 4);
  818. issue = rxrpc_u32_to_time64(be32_to_cpu(stamp));
  819. }
  820. p += 4;
  821. now = ktime_get_real_seconds();
  822. _debug("KIV ISSUE: %llx [%llx]", issue, now);
  823. /* check the ticket is in date */
  824. if (issue > now) {
  825. abort_code = RXKADNOAUTH;
  826. ret = -EKEYREJECTED;
  827. goto other_error;
  828. }
  829. if (issue < now - life) {
  830. abort_code = RXKADEXPIRED;
  831. ret = -EKEYEXPIRED;
  832. goto other_error;
  833. }
  834. *_expiry = issue + life;
  835. /* get the service name */
  836. name = Z(SNAME);
  837. _debug("KIV SNAME: %s", name);
  838. /* get the service instance name */
  839. name = Z(INST);
  840. _debug("KIV SINST: %s", name);
  841. return 0;
  842. bad_ticket:
  843. trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto);
  844. abort_code = RXKADBADTICKET;
  845. ret = -EPROTO;
  846. other_error:
  847. *_abort_code = abort_code;
  848. return ret;
  849. temporary_error:
  850. return ret;
  851. }
  852. /*
  853. * decrypt the response packet
  854. */
  855. static void rxkad_decrypt_response(struct rxrpc_connection *conn,
  856. struct rxkad_response *resp,
  857. const struct rxrpc_crypt *session_key)
  858. {
  859. SKCIPHER_REQUEST_ON_STACK(req, rxkad_ci);
  860. struct scatterlist sg[1];
  861. struct rxrpc_crypt iv;
  862. _enter(",,%08x%08x",
  863. ntohl(session_key->n[0]), ntohl(session_key->n[1]));
  864. ASSERT(rxkad_ci != NULL);
  865. mutex_lock(&rxkad_ci_mutex);
  866. if (crypto_skcipher_setkey(rxkad_ci, session_key->x,
  867. sizeof(*session_key)) < 0)
  868. BUG();
  869. memcpy(&iv, session_key, sizeof(iv));
  870. sg_init_table(sg, 1);
  871. sg_set_buf(sg, &resp->encrypted, sizeof(resp->encrypted));
  872. skcipher_request_set_tfm(req, rxkad_ci);
  873. skcipher_request_set_callback(req, 0, NULL, NULL);
  874. skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x);
  875. crypto_skcipher_decrypt(req);
  876. skcipher_request_zero(req);
  877. mutex_unlock(&rxkad_ci_mutex);
  878. _leave("");
  879. }
  880. /*
  881. * verify a response
  882. */
  883. static int rxkad_verify_response(struct rxrpc_connection *conn,
  884. struct sk_buff *skb,
  885. u32 *_abort_code)
  886. {
  887. struct rxkad_response *response;
  888. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  889. struct rxrpc_crypt session_key;
  890. const char *eproto;
  891. time64_t expiry;
  892. void *ticket;
  893. u32 abort_code, version, kvno, ticket_len, level;
  894. __be32 csum;
  895. int ret, i;
  896. _enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key));
  897. ret = -ENOMEM;
  898. response = kzalloc(sizeof(struct rxkad_response), GFP_NOFS);
  899. if (!response)
  900. goto temporary_error;
  901. eproto = tracepoint_string("rxkad_rsp_short");
  902. abort_code = RXKADPACKETSHORT;
  903. if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
  904. response, sizeof(*response)) < 0)
  905. goto protocol_error;
  906. if (!pskb_pull(skb, sizeof(*response)))
  907. BUG();
  908. version = ntohl(response->version);
  909. ticket_len = ntohl(response->ticket_len);
  910. kvno = ntohl(response->kvno);
  911. _proto("Rx RESPONSE %%%u { v=%u kv=%u tl=%u }",
  912. sp->hdr.serial, version, kvno, ticket_len);
  913. eproto = tracepoint_string("rxkad_rsp_ver");
  914. abort_code = RXKADINCONSISTENCY;
  915. if (version != RXKAD_VERSION)
  916. goto protocol_error;
  917. eproto = tracepoint_string("rxkad_rsp_tktlen");
  918. abort_code = RXKADTICKETLEN;
  919. if (ticket_len < 4 || ticket_len > MAXKRB5TICKETLEN)
  920. goto protocol_error;
  921. eproto = tracepoint_string("rxkad_rsp_unkkey");
  922. abort_code = RXKADUNKNOWNKEY;
  923. if (kvno >= RXKAD_TKT_TYPE_KERBEROS_V5)
  924. goto protocol_error;
  925. /* extract the kerberos ticket and decrypt and decode it */
  926. ret = -ENOMEM;
  927. ticket = kmalloc(ticket_len, GFP_NOFS);
  928. if (!ticket)
  929. goto temporary_error;
  930. eproto = tracepoint_string("rxkad_tkt_short");
  931. abort_code = RXKADPACKETSHORT;
  932. if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header),
  933. ticket, ticket_len) < 0)
  934. goto protocol_error_free;
  935. ret = rxkad_decrypt_ticket(conn, skb, ticket, ticket_len, &session_key,
  936. &expiry, _abort_code);
  937. if (ret < 0)
  938. goto temporary_error_free_resp;
  939. /* use the session key from inside the ticket to decrypt the
  940. * response */
  941. rxkad_decrypt_response(conn, response, &session_key);
  942. eproto = tracepoint_string("rxkad_rsp_param");
  943. abort_code = RXKADSEALEDINCON;
  944. if (ntohl(response->encrypted.epoch) != conn->proto.epoch)
  945. goto protocol_error_free;
  946. if (ntohl(response->encrypted.cid) != conn->proto.cid)
  947. goto protocol_error_free;
  948. if (ntohl(response->encrypted.securityIndex) != conn->security_ix)
  949. goto protocol_error_free;
  950. csum = response->encrypted.checksum;
  951. response->encrypted.checksum = 0;
  952. rxkad_calc_response_checksum(response);
  953. eproto = tracepoint_string("rxkad_rsp_csum");
  954. if (response->encrypted.checksum != csum)
  955. goto protocol_error_free;
  956. spin_lock(&conn->channel_lock);
  957. for (i = 0; i < RXRPC_MAXCALLS; i++) {
  958. struct rxrpc_call *call;
  959. u32 call_id = ntohl(response->encrypted.call_id[i]);
  960. eproto = tracepoint_string("rxkad_rsp_callid");
  961. if (call_id > INT_MAX)
  962. goto protocol_error_unlock;
  963. eproto = tracepoint_string("rxkad_rsp_callctr");
  964. if (call_id < conn->channels[i].call_counter)
  965. goto protocol_error_unlock;
  966. eproto = tracepoint_string("rxkad_rsp_callst");
  967. if (call_id > conn->channels[i].call_counter) {
  968. call = rcu_dereference_protected(
  969. conn->channels[i].call,
  970. lockdep_is_held(&conn->channel_lock));
  971. if (call && call->state < RXRPC_CALL_COMPLETE)
  972. goto protocol_error_unlock;
  973. conn->channels[i].call_counter = call_id;
  974. }
  975. }
  976. spin_unlock(&conn->channel_lock);
  977. eproto = tracepoint_string("rxkad_rsp_seq");
  978. abort_code = RXKADOUTOFSEQUENCE;
  979. if (ntohl(response->encrypted.inc_nonce) != conn->security_nonce + 1)
  980. goto protocol_error_free;
  981. eproto = tracepoint_string("rxkad_rsp_level");
  982. abort_code = RXKADLEVELFAIL;
  983. level = ntohl(response->encrypted.level);
  984. if (level > RXRPC_SECURITY_ENCRYPT)
  985. goto protocol_error_free;
  986. conn->params.security_level = level;
  987. /* create a key to hold the security data and expiration time - after
  988. * this the connection security can be handled in exactly the same way
  989. * as for a client connection */
  990. ret = rxrpc_get_server_data_key(conn, &session_key, expiry, kvno);
  991. if (ret < 0)
  992. goto temporary_error_free_ticket;
  993. kfree(ticket);
  994. kfree(response);
  995. _leave(" = 0");
  996. return 0;
  997. protocol_error_unlock:
  998. spin_unlock(&conn->channel_lock);
  999. protocol_error_free:
  1000. kfree(ticket);
  1001. protocol_error:
  1002. kfree(response);
  1003. trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto);
  1004. *_abort_code = abort_code;
  1005. return -EPROTO;
  1006. temporary_error_free_ticket:
  1007. kfree(ticket);
  1008. temporary_error_free_resp:
  1009. kfree(response);
  1010. temporary_error:
  1011. /* Ignore the response packet if we got a temporary error such as
  1012. * ENOMEM. We just want to send the challenge again. Note that we
  1013. * also come out this way if the ticket decryption fails.
  1014. */
  1015. return ret;
  1016. }
  1017. /*
  1018. * clear the connection security
  1019. */
  1020. static void rxkad_clear(struct rxrpc_connection *conn)
  1021. {
  1022. _enter("");
  1023. if (conn->cipher)
  1024. crypto_free_skcipher(conn->cipher);
  1025. }
  1026. /*
  1027. * Initialise the rxkad security service.
  1028. */
  1029. static int rxkad_init(void)
  1030. {
  1031. /* pin the cipher we need so that the crypto layer doesn't invoke
  1032. * keventd to go get it */
  1033. rxkad_ci = crypto_alloc_skcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC);
  1034. return PTR_ERR_OR_ZERO(rxkad_ci);
  1035. }
  1036. /*
  1037. * Clean up the rxkad security service.
  1038. */
  1039. static void rxkad_exit(void)
  1040. {
  1041. if (rxkad_ci)
  1042. crypto_free_skcipher(rxkad_ci);
  1043. }
  1044. /*
  1045. * RxRPC Kerberos-based security
  1046. */
  1047. const struct rxrpc_security rxkad = {
  1048. .name = "rxkad",
  1049. .security_index = RXRPC_SECURITY_RXKAD,
  1050. .init = rxkad_init,
  1051. .exit = rxkad_exit,
  1052. .init_connection_security = rxkad_init_connection_security,
  1053. .prime_packet_security = rxkad_prime_packet_security,
  1054. .secure_packet = rxkad_secure_packet,
  1055. .verify_packet = rxkad_verify_packet,
  1056. .locate_data = rxkad_locate_data,
  1057. .issue_challenge = rxkad_issue_challenge,
  1058. .respond_to_challenge = rxkad_respond_to_challenge,
  1059. .verify_response = rxkad_verify_response,
  1060. .clear = rxkad_clear,
  1061. };