s390xcap.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Copyright 2010-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <setjmp.h>
  13. #include <signal.h>
  14. #include "internal/cryptlib.h"
  15. #include "internal/ctype.h"
  16. #include "s390x_arch.h"
  17. #define LEN 128
  18. #define STR_(S) #S
  19. #define STR(S) STR_(S)
  20. #define TOK_FUNC(NAME) \
  21. (sscanf(tok_begin, \
  22. " " STR(NAME) " : %" STR(LEN) "[^:] : " \
  23. "%" STR(LEN) "s %" STR(LEN) "s ", \
  24. tok[0], tok[1], tok[2]) == 2) { \
  25. \
  26. off = (tok[0][0] == '~') ? 1 : 0; \
  27. if (sscanf(tok[0] + off, "%llx", &cap->NAME[0]) != 1) \
  28. goto ret; \
  29. if (off) \
  30. cap->NAME[0] = ~cap->NAME[0]; \
  31. \
  32. off = (tok[1][0] == '~') ? 1 : 0; \
  33. if (sscanf(tok[1] + off, "%llx", &cap->NAME[1]) != 1) \
  34. goto ret; \
  35. if (off) \
  36. cap->NAME[1] = ~cap->NAME[1]; \
  37. }
  38. #define TOK_CPU(NAME) \
  39. (sscanf(tok_begin, \
  40. " %" STR(LEN) "s %" STR(LEN) "s ", \
  41. tok[0], tok[1]) == 1 \
  42. && !strcmp(tok[0], #NAME)) { \
  43. memcpy(cap, &NAME, sizeof(*cap)); \
  44. }
  45. static sigjmp_buf ill_jmp;
  46. static void ill_handler(int sig)
  47. {
  48. siglongjmp(ill_jmp, sig);
  49. }
  50. static const char *env;
  51. static int parse_env(struct OPENSSL_s390xcap_st *cap);
  52. void OPENSSL_s390x_facilities(void);
  53. void OPENSSL_s390x_functions(void);
  54. void OPENSSL_vx_probe(void);
  55. struct OPENSSL_s390xcap_st OPENSSL_s390xcap_P;
  56. void OPENSSL_cpuid_setup(void)
  57. {
  58. sigset_t oset;
  59. struct sigaction ill_act, oact;
  60. struct OPENSSL_s390xcap_st cap;
  61. if (OPENSSL_s390xcap_P.stfle[0])
  62. return;
  63. /* set a bit that will not be tested later */
  64. OPENSSL_s390xcap_P.stfle[0] |= S390X_CAPBIT(0);
  65. env = getenv("OPENSSL_s390xcap");
  66. if (env != NULL) {
  67. if (!parse_env(&cap))
  68. env = NULL;
  69. }
  70. memset(&ill_act, 0, sizeof(ill_act));
  71. ill_act.sa_handler = ill_handler;
  72. sigfillset(&ill_act.sa_mask);
  73. sigdelset(&ill_act.sa_mask, SIGILL);
  74. sigdelset(&ill_act.sa_mask, SIGFPE);
  75. sigdelset(&ill_act.sa_mask, SIGTRAP);
  76. sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
  77. sigaction(SIGILL, &ill_act, &oact);
  78. sigaction(SIGFPE, &ill_act, &oact);
  79. /* protection against missing store-facility-list-extended */
  80. if (sigsetjmp(ill_jmp, 1) == 0)
  81. OPENSSL_s390x_facilities();
  82. if (env != NULL) {
  83. OPENSSL_s390xcap_P.stfle[0] &= cap.stfle[0];
  84. OPENSSL_s390xcap_P.stfle[1] &= cap.stfle[1];
  85. OPENSSL_s390xcap_P.stfle[2] &= cap.stfle[2];
  86. }
  87. /* protection against disabled vector facility */
  88. if ((OPENSSL_s390xcap_P.stfle[2] & S390X_CAPBIT(S390X_VX))
  89. && (sigsetjmp(ill_jmp, 1) == 0)) {
  90. OPENSSL_vx_probe();
  91. } else {
  92. OPENSSL_s390xcap_P.stfle[2] &= ~(S390X_CAPBIT(S390X_VX)
  93. | S390X_CAPBIT(S390X_VXD)
  94. | S390X_CAPBIT(S390X_VXE));
  95. }
  96. sigaction(SIGFPE, &oact, NULL);
  97. sigaction(SIGILL, &oact, NULL);
  98. sigprocmask(SIG_SETMASK, &oset, NULL);
  99. OPENSSL_s390x_functions();
  100. if (env != NULL) {
  101. OPENSSL_s390xcap_P.kimd[0] &= cap.kimd[0];
  102. OPENSSL_s390xcap_P.kimd[1] &= cap.kimd[1];
  103. OPENSSL_s390xcap_P.klmd[0] &= cap.klmd[0];
  104. OPENSSL_s390xcap_P.klmd[1] &= cap.klmd[1];
  105. OPENSSL_s390xcap_P.km[0] &= cap.km[0];
  106. OPENSSL_s390xcap_P.km[1] &= cap.km[1];
  107. OPENSSL_s390xcap_P.kmc[0] &= cap.kmc[0];
  108. OPENSSL_s390xcap_P.kmc[1] &= cap.kmc[1];
  109. OPENSSL_s390xcap_P.kmac[0] &= cap.kmac[0];
  110. OPENSSL_s390xcap_P.kmac[1] &= cap.kmac[1];
  111. OPENSSL_s390xcap_P.kmctr[0] &= cap.kmctr[0];
  112. OPENSSL_s390xcap_P.kmctr[1] &= cap.kmctr[1];
  113. OPENSSL_s390xcap_P.kmo[0] &= cap.kmo[0];
  114. OPENSSL_s390xcap_P.kmo[1] &= cap.kmo[1];
  115. OPENSSL_s390xcap_P.kmf[0] &= cap.kmf[0];
  116. OPENSSL_s390xcap_P.kmf[1] &= cap.kmf[1];
  117. OPENSSL_s390xcap_P.prno[0] &= cap.prno[0];
  118. OPENSSL_s390xcap_P.prno[1] &= cap.prno[1];
  119. OPENSSL_s390xcap_P.kma[0] &= cap.kma[0];
  120. OPENSSL_s390xcap_P.kma[1] &= cap.kma[1];
  121. }
  122. }
  123. static int parse_env(struct OPENSSL_s390xcap_st *cap)
  124. {
  125. /*-
  126. * CPU model data
  127. * (only the STFLE- and QUERY-bits relevant to libcrypto are set)
  128. */
  129. /*-
  130. * z900 (2000) - z/Architecture POP SA22-7832-00
  131. * Facility detection would fail on real hw (no STFLE).
  132. */
  133. static const struct OPENSSL_s390xcap_st z900 = {
  134. /*.stfle = */{0ULL, 0ULL, 0ULL, 0ULL},
  135. /*.kimd = */{0ULL, 0ULL},
  136. /*.klmd = */{0ULL, 0ULL},
  137. /*.km = */{0ULL, 0ULL},
  138. /*.kmc = */{0ULL, 0ULL},
  139. /*.kmac = */{0ULL, 0ULL},
  140. /*.kmctr = */{0ULL, 0ULL},
  141. /*.kmo = */{0ULL, 0ULL},
  142. /*.kmf = */{0ULL, 0ULL},
  143. /*.prno = */{0ULL, 0ULL},
  144. /*.kma = */{0ULL, 0ULL},
  145. };
  146. /*-
  147. * z990 (2003) - z/Architecture POP SA22-7832-02
  148. * Implements MSA. Facility detection would fail on real hw (no STFLE).
  149. */
  150. static const struct OPENSSL_s390xcap_st z990 = {
  151. /*.stfle = */{S390X_CAPBIT(S390X_MSA),
  152. 0ULL, 0ULL, 0ULL},
  153. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  154. | S390X_CAPBIT(S390X_SHA_1),
  155. 0ULL},
  156. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  157. | S390X_CAPBIT(S390X_SHA_1),
  158. 0ULL},
  159. /*.km = */{S390X_CAPBIT(S390X_QUERY),
  160. 0ULL},
  161. /*.kmc = */{S390X_CAPBIT(S390X_QUERY),
  162. 0ULL},
  163. /*.kmac = */{S390X_CAPBIT(S390X_QUERY),
  164. 0ULL},
  165. /*.kmctr = */{0ULL, 0ULL},
  166. /*.kmo = */{0ULL, 0ULL},
  167. /*.kmf = */{0ULL, 0ULL},
  168. /*.prno = */{0ULL, 0ULL},
  169. /*.kma = */{0ULL, 0ULL},
  170. };
  171. /*-
  172. * z9 (2005) - z/Architecture POP SA22-7832-04
  173. * Implements MSA and MSA1.
  174. */
  175. static const struct OPENSSL_s390xcap_st z9 = {
  176. /*.stfle = */{S390X_CAPBIT(S390X_MSA)
  177. | S390X_CAPBIT(S390X_STCKF),
  178. 0ULL, 0ULL, 0ULL},
  179. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  180. | S390X_CAPBIT(S390X_SHA_1)
  181. | S390X_CAPBIT(S390X_SHA_256),
  182. 0ULL},
  183. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  184. | S390X_CAPBIT(S390X_SHA_1)
  185. | S390X_CAPBIT(S390X_SHA_256),
  186. 0ULL},
  187. /*.km = */{S390X_CAPBIT(S390X_QUERY)
  188. | S390X_CAPBIT(S390X_AES_128),
  189. 0ULL},
  190. /*.kmc = */{S390X_CAPBIT(S390X_QUERY)
  191. | S390X_CAPBIT(S390X_AES_128),
  192. 0ULL},
  193. /*.kmac = */{S390X_CAPBIT(S390X_QUERY),
  194. 0ULL},
  195. /*.kmctr = */{0ULL, 0ULL},
  196. /*.kmo = */{0ULL, 0ULL},
  197. /*.kmf = */{0ULL, 0ULL},
  198. /*.prno = */{0ULL, 0ULL},
  199. /*.kma = */{0ULL, 0ULL},
  200. };
  201. /*-
  202. * z10 (2008) - z/Architecture POP SA22-7832-06
  203. * Implements MSA and MSA1-2.
  204. */
  205. static const struct OPENSSL_s390xcap_st z10 = {
  206. /*.stfle = */{S390X_CAPBIT(S390X_MSA)
  207. | S390X_CAPBIT(S390X_STCKF),
  208. 0ULL, 0ULL, 0ULL},
  209. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  210. | S390X_CAPBIT(S390X_SHA_1)
  211. | S390X_CAPBIT(S390X_SHA_256)
  212. | S390X_CAPBIT(S390X_SHA_512),
  213. 0ULL},
  214. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  215. | S390X_CAPBIT(S390X_SHA_1)
  216. | S390X_CAPBIT(S390X_SHA_256)
  217. | S390X_CAPBIT(S390X_SHA_512),
  218. 0ULL},
  219. /*.km = */{S390X_CAPBIT(S390X_QUERY)
  220. | S390X_CAPBIT(S390X_AES_128)
  221. | S390X_CAPBIT(S390X_AES_192)
  222. | S390X_CAPBIT(S390X_AES_256),
  223. 0ULL},
  224. /*.kmc = */{S390X_CAPBIT(S390X_QUERY)
  225. | S390X_CAPBIT(S390X_AES_128)
  226. | S390X_CAPBIT(S390X_AES_192)
  227. | S390X_CAPBIT(S390X_AES_256),
  228. 0ULL},
  229. /*.kmac = */{S390X_CAPBIT(S390X_QUERY),
  230. 0ULL},
  231. /*.kmctr = */{0ULL, 0ULL},
  232. /*.kmo = */{0ULL, 0ULL},
  233. /*.kmf = */{0ULL, 0ULL},
  234. /*.prno = */{0ULL, 0ULL},
  235. /*.kma = */{0ULL, 0ULL},
  236. };
  237. /*-
  238. * z196 (2010) - z/Architecture POP SA22-7832-08
  239. * Implements MSA and MSA1-4.
  240. */
  241. static const struct OPENSSL_s390xcap_st z196 = {
  242. /*.stfle = */{S390X_CAPBIT(S390X_MSA)
  243. | S390X_CAPBIT(S390X_STCKF),
  244. S390X_CAPBIT(S390X_MSA3)
  245. | S390X_CAPBIT(S390X_MSA4),
  246. 0ULL, 0ULL},
  247. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  248. | S390X_CAPBIT(S390X_SHA_1)
  249. | S390X_CAPBIT(S390X_SHA_256)
  250. | S390X_CAPBIT(S390X_SHA_512),
  251. S390X_CAPBIT(S390X_GHASH)},
  252. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  253. | S390X_CAPBIT(S390X_SHA_1)
  254. | S390X_CAPBIT(S390X_SHA_256)
  255. | S390X_CAPBIT(S390X_SHA_512),
  256. 0ULL},
  257. /*.km = */{S390X_CAPBIT(S390X_QUERY)
  258. | S390X_CAPBIT(S390X_AES_128)
  259. | S390X_CAPBIT(S390X_AES_192)
  260. | S390X_CAPBIT(S390X_AES_256)
  261. | S390X_CAPBIT(S390X_XTS_AES_128)
  262. | S390X_CAPBIT(S390X_XTS_AES_256),
  263. 0ULL},
  264. /*.kmc = */{S390X_CAPBIT(S390X_QUERY)
  265. | S390X_CAPBIT(S390X_AES_128)
  266. | S390X_CAPBIT(S390X_AES_192)
  267. | S390X_CAPBIT(S390X_AES_256),
  268. 0ULL},
  269. /*.kmac = */{S390X_CAPBIT(S390X_QUERY)
  270. | S390X_CAPBIT(S390X_AES_128)
  271. | S390X_CAPBIT(S390X_AES_192)
  272. | S390X_CAPBIT(S390X_AES_256),
  273. 0ULL},
  274. /*.kmctr = */{S390X_CAPBIT(S390X_QUERY)
  275. | S390X_CAPBIT(S390X_AES_128)
  276. | S390X_CAPBIT(S390X_AES_192)
  277. | S390X_CAPBIT(S390X_AES_256),
  278. 0ULL},
  279. /*.kmo = */{S390X_CAPBIT(S390X_QUERY)
  280. | S390X_CAPBIT(S390X_AES_128)
  281. | S390X_CAPBIT(S390X_AES_192)
  282. | S390X_CAPBIT(S390X_AES_256),
  283. 0ULL},
  284. /*.kmf = */{S390X_CAPBIT(S390X_QUERY)
  285. | S390X_CAPBIT(S390X_AES_128)
  286. | S390X_CAPBIT(S390X_AES_192)
  287. | S390X_CAPBIT(S390X_AES_256),
  288. 0ULL},
  289. /*.prno = */{0ULL, 0ULL},
  290. /*.kma = */{0ULL, 0ULL},
  291. };
  292. /*-
  293. * zEC12 (2012) - z/Architecture POP SA22-7832-09
  294. * Implements MSA and MSA1-4.
  295. */
  296. static const struct OPENSSL_s390xcap_st zEC12 = {
  297. /*.stfle = */{S390X_CAPBIT(S390X_MSA)
  298. | S390X_CAPBIT(S390X_STCKF),
  299. S390X_CAPBIT(S390X_MSA3)
  300. | S390X_CAPBIT(S390X_MSA4),
  301. 0ULL, 0ULL},
  302. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  303. | S390X_CAPBIT(S390X_SHA_1)
  304. | S390X_CAPBIT(S390X_SHA_256)
  305. | S390X_CAPBIT(S390X_SHA_512),
  306. S390X_CAPBIT(S390X_GHASH)},
  307. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  308. | S390X_CAPBIT(S390X_SHA_1)
  309. | S390X_CAPBIT(S390X_SHA_256)
  310. | S390X_CAPBIT(S390X_SHA_512),
  311. 0ULL},
  312. /*.km = */{S390X_CAPBIT(S390X_QUERY)
  313. | S390X_CAPBIT(S390X_AES_128)
  314. | S390X_CAPBIT(S390X_AES_192)
  315. | S390X_CAPBIT(S390X_AES_256)
  316. | S390X_CAPBIT(S390X_XTS_AES_128)
  317. | S390X_CAPBIT(S390X_XTS_AES_256),
  318. 0ULL},
  319. /*.kmc = */{S390X_CAPBIT(S390X_QUERY)
  320. | S390X_CAPBIT(S390X_AES_128)
  321. | S390X_CAPBIT(S390X_AES_192)
  322. | S390X_CAPBIT(S390X_AES_256),
  323. 0ULL},
  324. /*.kmac = */{S390X_CAPBIT(S390X_QUERY)
  325. | S390X_CAPBIT(S390X_AES_128)
  326. | S390X_CAPBIT(S390X_AES_192)
  327. | S390X_CAPBIT(S390X_AES_256),
  328. 0ULL},
  329. /*.kmctr = */{S390X_CAPBIT(S390X_QUERY)
  330. | S390X_CAPBIT(S390X_AES_128)
  331. | S390X_CAPBIT(S390X_AES_192)
  332. | S390X_CAPBIT(S390X_AES_256),
  333. 0ULL},
  334. /*.kmo = */{S390X_CAPBIT(S390X_QUERY)
  335. | S390X_CAPBIT(S390X_AES_128)
  336. | S390X_CAPBIT(S390X_AES_192)
  337. | S390X_CAPBIT(S390X_AES_256),
  338. 0ULL},
  339. /*.kmf = */{S390X_CAPBIT(S390X_QUERY)
  340. | S390X_CAPBIT(S390X_AES_128)
  341. | S390X_CAPBIT(S390X_AES_192)
  342. | S390X_CAPBIT(S390X_AES_256),
  343. 0ULL},
  344. /*.prno = */{0ULL, 0ULL},
  345. /*.kma = */{0ULL, 0ULL},
  346. };
  347. /*-
  348. * z13 (2015) - z/Architecture POP SA22-7832-10
  349. * Implements MSA and MSA1-5.
  350. */
  351. static const struct OPENSSL_s390xcap_st z13 = {
  352. /*.stfle = */{S390X_CAPBIT(S390X_MSA)
  353. | S390X_CAPBIT(S390X_STCKF)
  354. | S390X_CAPBIT(S390X_MSA5),
  355. S390X_CAPBIT(S390X_MSA3)
  356. | S390X_CAPBIT(S390X_MSA4),
  357. S390X_CAPBIT(S390X_VX),
  358. 0ULL},
  359. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  360. | S390X_CAPBIT(S390X_SHA_1)
  361. | S390X_CAPBIT(S390X_SHA_256)
  362. | S390X_CAPBIT(S390X_SHA_512),
  363. S390X_CAPBIT(S390X_GHASH)},
  364. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  365. | S390X_CAPBIT(S390X_SHA_1)
  366. | S390X_CAPBIT(S390X_SHA_256)
  367. | S390X_CAPBIT(S390X_SHA_512),
  368. 0ULL},
  369. /*.km = */{S390X_CAPBIT(S390X_QUERY)
  370. | S390X_CAPBIT(S390X_AES_128)
  371. | S390X_CAPBIT(S390X_AES_192)
  372. | S390X_CAPBIT(S390X_AES_256)
  373. | S390X_CAPBIT(S390X_XTS_AES_128)
  374. | S390X_CAPBIT(S390X_XTS_AES_256),
  375. 0ULL},
  376. /*.kmc = */{S390X_CAPBIT(S390X_QUERY)
  377. | S390X_CAPBIT(S390X_AES_128)
  378. | S390X_CAPBIT(S390X_AES_192)
  379. | S390X_CAPBIT(S390X_AES_256),
  380. 0ULL},
  381. /*.kmac = */{S390X_CAPBIT(S390X_QUERY)
  382. | S390X_CAPBIT(S390X_AES_128)
  383. | S390X_CAPBIT(S390X_AES_192)
  384. | S390X_CAPBIT(S390X_AES_256),
  385. 0ULL},
  386. /*.kmctr = */{S390X_CAPBIT(S390X_QUERY)
  387. | S390X_CAPBIT(S390X_AES_128)
  388. | S390X_CAPBIT(S390X_AES_192)
  389. | S390X_CAPBIT(S390X_AES_256),
  390. 0ULL},
  391. /*.kmo = */{S390X_CAPBIT(S390X_QUERY)
  392. | S390X_CAPBIT(S390X_AES_128)
  393. | S390X_CAPBIT(S390X_AES_192)
  394. | S390X_CAPBIT(S390X_AES_256),
  395. 0ULL},
  396. /*.kmf = */{S390X_CAPBIT(S390X_QUERY)
  397. | S390X_CAPBIT(S390X_AES_128)
  398. | S390X_CAPBIT(S390X_AES_192)
  399. | S390X_CAPBIT(S390X_AES_256),
  400. 0ULL},
  401. /*.prno = */{S390X_CAPBIT(S390X_QUERY)
  402. | S390X_CAPBIT(S390X_SHA_512_DRNG),
  403. 0ULL},
  404. /*.kma = */{0ULL, 0ULL},
  405. };
  406. /*-
  407. * z14 (2017) - z/Architecture POP SA22-7832-11
  408. * Implements MSA and MSA1-8.
  409. */
  410. static const struct OPENSSL_s390xcap_st z14 = {
  411. /*.stfle = */{S390X_CAPBIT(S390X_MSA)
  412. | S390X_CAPBIT(S390X_STCKF)
  413. | S390X_CAPBIT(S390X_MSA5),
  414. S390X_CAPBIT(S390X_MSA3)
  415. | S390X_CAPBIT(S390X_MSA4),
  416. S390X_CAPBIT(S390X_VX)
  417. | S390X_CAPBIT(S390X_VXD)
  418. | S390X_CAPBIT(S390X_VXE)
  419. | S390X_CAPBIT(S390X_MSA8),
  420. 0ULL},
  421. /*.kimd = */{S390X_CAPBIT(S390X_QUERY)
  422. | S390X_CAPBIT(S390X_SHA_1)
  423. | S390X_CAPBIT(S390X_SHA_256)
  424. | S390X_CAPBIT(S390X_SHA_512)
  425. | S390X_CAPBIT(S390X_SHA3_224)
  426. | S390X_CAPBIT(S390X_SHA3_256)
  427. | S390X_CAPBIT(S390X_SHA3_384)
  428. | S390X_CAPBIT(S390X_SHA3_512)
  429. | S390X_CAPBIT(S390X_SHAKE_128)
  430. | S390X_CAPBIT(S390X_SHAKE_256),
  431. S390X_CAPBIT(S390X_GHASH)},
  432. /*.klmd = */{S390X_CAPBIT(S390X_QUERY)
  433. | S390X_CAPBIT(S390X_SHA_1)
  434. | S390X_CAPBIT(S390X_SHA_256)
  435. | S390X_CAPBIT(S390X_SHA_512)
  436. | S390X_CAPBIT(S390X_SHA3_224)
  437. | S390X_CAPBIT(S390X_SHA3_256)
  438. | S390X_CAPBIT(S390X_SHA3_384)
  439. | S390X_CAPBIT(S390X_SHA3_512)
  440. | S390X_CAPBIT(S390X_SHAKE_128)
  441. | S390X_CAPBIT(S390X_SHAKE_256),
  442. 0ULL},
  443. /*.km = */{S390X_CAPBIT(S390X_QUERY)
  444. | S390X_CAPBIT(S390X_AES_128)
  445. | S390X_CAPBIT(S390X_AES_192)
  446. | S390X_CAPBIT(S390X_AES_256)
  447. | S390X_CAPBIT(S390X_XTS_AES_128)
  448. | S390X_CAPBIT(S390X_XTS_AES_256),
  449. 0ULL},
  450. /*.kmc = */{S390X_CAPBIT(S390X_QUERY)
  451. | S390X_CAPBIT(S390X_AES_128)
  452. | S390X_CAPBIT(S390X_AES_192)
  453. | S390X_CAPBIT(S390X_AES_256),
  454. 0ULL},
  455. /*.kmac = */{S390X_CAPBIT(S390X_QUERY)
  456. | S390X_CAPBIT(S390X_AES_128)
  457. | S390X_CAPBIT(S390X_AES_192)
  458. | S390X_CAPBIT(S390X_AES_256),
  459. 0ULL},
  460. /*.kmctr = */{S390X_CAPBIT(S390X_QUERY)
  461. | S390X_CAPBIT(S390X_AES_128)
  462. | S390X_CAPBIT(S390X_AES_192)
  463. | S390X_CAPBIT(S390X_AES_256),
  464. 0ULL},
  465. /*.kmo = */{S390X_CAPBIT(S390X_QUERY)
  466. | S390X_CAPBIT(S390X_AES_128)
  467. | S390X_CAPBIT(S390X_AES_192)
  468. | S390X_CAPBIT(S390X_AES_256),
  469. 0ULL},
  470. /*.kmf = */{S390X_CAPBIT(S390X_QUERY)
  471. | S390X_CAPBIT(S390X_AES_128)
  472. | S390X_CAPBIT(S390X_AES_192)
  473. | S390X_CAPBIT(S390X_AES_256),
  474. 0ULL},
  475. /*.prno = */{S390X_CAPBIT(S390X_QUERY)
  476. | S390X_CAPBIT(S390X_SHA_512_DRNG),
  477. S390X_CAPBIT(S390X_TRNG)},
  478. /*.kma = */{S390X_CAPBIT(S390X_QUERY)
  479. | S390X_CAPBIT(S390X_AES_128)
  480. | S390X_CAPBIT(S390X_AES_192)
  481. | S390X_CAPBIT(S390X_AES_256),
  482. 0ULL},
  483. };
  484. char *tok_begin, *tok_end, *buff, tok[S390X_STFLE_MAX][LEN + 1];
  485. int rc, off, i, n;
  486. buff = malloc(strlen(env) + 1);
  487. if (buff == NULL)
  488. return 0;
  489. rc = 0;
  490. memset(cap, ~0, sizeof(*cap));
  491. strcpy(buff, env);
  492. tok_begin = buff + strspn(buff, ";");
  493. strtok(tok_begin, ";");
  494. tok_end = strtok(NULL, ";");
  495. while (tok_begin != NULL) {
  496. /* stfle token */
  497. if ((n = sscanf(tok_begin,
  498. " stfle : %" STR(LEN) "[^:] : "
  499. "%" STR(LEN) "[^:] : %" STR(LEN) "s ",
  500. tok[0], tok[1], tok[2]))) {
  501. for (i = 0; i < n; i++) {
  502. off = (tok[i][0] == '~') ? 1 : 0;
  503. if (sscanf(tok[i] + off, "%llx", &cap->stfle[i]) != 1)
  504. goto ret;
  505. if (off)
  506. cap->stfle[i] = ~cap->stfle[i];
  507. }
  508. }
  509. /* query function tokens */
  510. else if TOK_FUNC(kimd)
  511. else if TOK_FUNC(klmd)
  512. else if TOK_FUNC(km)
  513. else if TOK_FUNC(kmc)
  514. else if TOK_FUNC(kmac)
  515. else if TOK_FUNC(kmctr)
  516. else if TOK_FUNC(kmo)
  517. else if TOK_FUNC(kmf)
  518. else if TOK_FUNC(prno)
  519. else if TOK_FUNC(kma)
  520. /* CPU model tokens */
  521. else if TOK_CPU(z900)
  522. else if TOK_CPU(z990)
  523. else if TOK_CPU(z9)
  524. else if TOK_CPU(z10)
  525. else if TOK_CPU(z196)
  526. else if TOK_CPU(zEC12)
  527. else if TOK_CPU(z13)
  528. else if TOK_CPU(z14)
  529. /* whitespace(ignored) or invalid tokens */
  530. else {
  531. while (*tok_begin != '\0') {
  532. if (!ossl_isspace(*tok_begin))
  533. goto ret;
  534. tok_begin++;
  535. }
  536. }
  537. tok_begin = tok_end;
  538. tok_end = strtok(NULL, ";");
  539. }
  540. rc = 1;
  541. ret:
  542. free(buff);
  543. return rc;
  544. }