/hphp/runtime/ext/mcrypt/ext_mcrypt.php

https://github.com/soitun/hiphop-php · PHP · 535 lines · 117 code · 37 blank · 381 comment · 0 complexity · 3c825f46fb7ed80a3658ae034d267cfa MD5 · raw file

  1. <?hh // partial
  2. /**
  3. * Encrypts/decrypts data in CBC mode
  4. *
  5. * @param string $cipher -
  6. * @param string $key -
  7. * @param string $data -
  8. * @param int $mode -
  9. * @param string $iv -
  10. *
  11. * @return string -
  12. */
  13. <<__Native>>
  14. function mcrypt_cbc(string $cipher,
  15. string $key,
  16. string $data,
  17. mixed $mode,
  18. ?string $iv = null): mixed;
  19. /**
  20. * Encrypts/decrypts data in CFB mode
  21. *
  22. * @param string $cipher -
  23. * @param string $key -
  24. * @param string $data -
  25. * @param int $mode -
  26. * @param string $iv -
  27. *
  28. * @return string -
  29. */
  30. <<__Native>>
  31. function mcrypt_cfb(string $cipher,
  32. string $key,
  33. string $data,
  34. mixed $mode,
  35. ?string $iv = null): mixed;
  36. /**
  37. * Creates an initialization vector (IV) from a random source
  38. *
  39. * @param int $size - The size of the IV.
  40. * @param int $source - The source of the IV. The source can be
  41. * MCRYPT_RAND (system random number generator), MCRYPT_DEV_RANDOM (read
  42. * data from /dev/random) and MCRYPT_DEV_URANDOM (read data from
  43. * /dev/urandom). Prior to 5.3.0, MCRYPT_RAND was the only one supported
  44. * on Windows.
  45. *
  46. * @return string - Returns the initialization vector, or FALSE on error.
  47. */
  48. <<__Native>>
  49. function mcrypt_create_iv(int $size,
  50. int $source = MCRYPT_DEV_RANDOM): mixed;
  51. /**
  52. * Decrypts crypttext with given parameters
  53. *
  54. * @param string $cipher -
  55. * @param string $key - The key with which the data was encrypted. If
  56. * it's smaller than the required keysize, it is padded with '\0'.
  57. * @param string $data - The data that will be decrypted with the given
  58. * cipher and mode. If the size of the data is not n * blocksize, the
  59. * data will be padded with '\0'.
  60. * @param string $mode -
  61. * @param string $iv -
  62. *
  63. * @return string - Returns the decrypted data as a string.
  64. */
  65. <<__Native>>
  66. function mcrypt_decrypt(string $cipher,
  67. string $key,
  68. string $data,
  69. string $mode,
  70. ?string $iv = null): mixed;
  71. /**
  72. * Deprecated: Encrypts/decrypts data in ECB mode
  73. *
  74. * @param string $cipher -
  75. * @param string $key -
  76. * @param string $data -
  77. * @param int $mode -
  78. * @param string $iv -
  79. *
  80. * @return string -
  81. */
  82. <<__Native>>
  83. function mcrypt_ecb(string $cipher,
  84. string $key,
  85. string $data,
  86. mixed $mode,
  87. ?string $iv = null): mixed;
  88. /**
  89. * Returns the name of the opened algorithm
  90. *
  91. * @param resource $td - The encryption descriptor.
  92. *
  93. * @return string - Returns the name of the opened algorithm as a string.
  94. */
  95. <<__Native>>
  96. function mcrypt_enc_get_algorithms_name(resource $td): mixed;
  97. /**
  98. * Returns the blocksize of the opened algorithm
  99. *
  100. * @param resource $td - The encryption descriptor.
  101. *
  102. * @return int - Returns the block size of the specified algorithm in
  103. * bytes.
  104. */
  105. <<__Native>>
  106. function mcrypt_enc_get_block_size(resource $td): mixed;
  107. /**
  108. * Returns the size of the IV of the opened algorithm
  109. *
  110. * @param resource $td - The encryption descriptor.
  111. *
  112. * @return int - Returns the size of the IV, or 0 if the IV is ignored by
  113. * the algorithm.
  114. */
  115. <<__Native>>
  116. function mcrypt_enc_get_iv_size(resource $td): mixed;
  117. /**
  118. * Returns the maximum supported keysize of the opened mode
  119. *
  120. * @param resource $td - The encryption descriptor.
  121. *
  122. * @return int - Returns the maximum supported key size of the algorithm
  123. * in bytes.
  124. */
  125. <<__Native>>
  126. function mcrypt_enc_get_key_size(resource $td): mixed;
  127. /**
  128. * Returns the name of the opened mode
  129. *
  130. * @param resource $td - The encryption descriptor.
  131. *
  132. * @return string - Returns the name as a string.
  133. */
  134. <<__Native>>
  135. function mcrypt_enc_get_modes_name(resource $td): mixed;
  136. /**
  137. * Returns an array with the supported keysizes of the opened algorithm
  138. *
  139. * @param resource $td - The encryption descriptor.
  140. *
  141. * @return array - Returns an array with the key sizes supported by the
  142. * algorithm specified by the encryption descriptor. If it returns an
  143. * empty array then all key sizes between 1 and mcrypt_enc_get_key_size()
  144. * are supported by the algorithm.
  145. */
  146. <<__Native>>
  147. function mcrypt_enc_get_supported_key_sizes(resource $td): mixed;
  148. /**
  149. * Checks whether the encryption of the opened mode works on blocks
  150. *
  151. * @param resource $td - The encryption descriptor.
  152. *
  153. * @return bool - Returns TRUE if the mode is for use with block
  154. * algorithms, otherwise it returns FALSE.
  155. */
  156. <<__Native>>
  157. function mcrypt_enc_is_block_algorithm_mode(resource $td): bool;
  158. /**
  159. * Checks whether the algorithm of the opened mode is a block algorithm
  160. *
  161. * @param resource $td - The encryption descriptor.
  162. *
  163. * @return bool - Returns TRUE if the algorithm is a block algorithm or
  164. * FALSE if it is a stream one.
  165. */
  166. <<__Native>>
  167. function mcrypt_enc_is_block_algorithm(resource $td): bool;
  168. /**
  169. * Checks whether the opened mode outputs blocks
  170. *
  171. * @param resource $td - The encryption descriptor.
  172. *
  173. * @return bool - Returns TRUE if the mode outputs blocks of bytes, or
  174. * FALSE if it outputs just bytes.
  175. */
  176. <<__Native>>
  177. function mcrypt_enc_is_block_mode(resource $td): bool;
  178. /**
  179. * Runs a self test on the opened module
  180. *
  181. * @param resource $td - The encryption descriptor.
  182. *
  183. * @return int - If the self test succeeds it returns FALSE. In case of
  184. * an error, it returns TRUE.
  185. */
  186. <<__Native>>
  187. function mcrypt_enc_self_test(resource $td): mixed;
  188. /**
  189. * Encrypts plaintext with given parameters
  190. *
  191. * @param string $cipher -
  192. * @param string $key - The key with which the data will be encrypted. If
  193. * it's smaller than the required keysize, it is padded with '\0'. It is
  194. * better not to use ASCII strings for keys. It is recommended to use
  195. * the mhash functions to create a key from a string.
  196. * @param string $data - The data that will be encrypted with the given
  197. * cipher and mode. If the size of the data is not n * blocksize, the
  198. * data will be padded with '\0'. The returned crypttext can be larger
  199. * than the size of the data that was given by data.
  200. * @param string $mode -
  201. * @param string $iv -
  202. *
  203. * @return string - Returns the encrypted data, as a string.
  204. */
  205. <<__Native>>
  206. function mcrypt_encrypt(string $cipher,
  207. string $key,
  208. string $data,
  209. string $mode,
  210. ?string $iv = null): mixed;
  211. /**
  212. * This function deinitializes an encryption module
  213. *
  214. * @param resource $td - The encryption descriptor.
  215. *
  216. * @return bool -
  217. */
  218. <<__Native>>
  219. function mcrypt_generic_deinit(resource $td): bool;
  220. /**
  221. * This function terminates encryption
  222. *
  223. * @param resource $td -
  224. *
  225. * @return bool -
  226. */
  227. <<__Native>>
  228. function mcrypt_generic_end(resource $td): bool;
  229. /**
  230. * This function initializes all buffers needed for encryption
  231. *
  232. * @param resource $td - The encryption descriptor.
  233. * @param string $key - The maximum length of the key should be the one
  234. * obtained by calling mcrypt_enc_get_key_size() and every value smaller
  235. * than this is legal.
  236. * @param string $iv - The IV should normally have the size of the
  237. * algorithms block size, but you must obtain the size by calling
  238. * mcrypt_enc_get_iv_size(). IV is ignored in ECB. IV MUST exist in CFB,
  239. * CBC, STREAM, nOFB and OFB modes. It needs to be random and unique (but
  240. * not secret). The same IV must be used for encryption/decryption. If
  241. * you do not want to use it you should set it to zeros, but this is not
  242. * recommended.
  243. *
  244. * @return int - The function returns a negative value on error: -3 when
  245. * the key length was incorrect, -4 when there was a memory allocation
  246. * problem and any other return value is an unknown error. If an error
  247. * occurs a warning will be displayed accordingly. FALSE is returned if
  248. * incorrect parameters were passed.
  249. */
  250. <<__Native>>
  251. function mcrypt_generic_init(resource $td,
  252. string $key,
  253. string $iv): mixed;
  254. /**
  255. * This function encrypts data
  256. *
  257. * @param resource $td - The encryption descriptor. The encryption
  258. * handle should always be initialized with mcrypt_generic_init() with a
  259. * key and an IV before calling this function. Where the encryption is
  260. * done, you should free the encryption buffers by calling
  261. * mcrypt_generic_deinit(). See mcrypt_module_open() for an example.
  262. * @param string $data - The data to encrypt.
  263. *
  264. * @return string - Returns the encrypted data.
  265. */
  266. <<__Native>>
  267. function mcrypt_generic(resource $td,
  268. string $data): mixed;
  269. /**
  270. * Gets the block size of the specified cipher
  271. *
  272. * @param string $cipher -
  273. * @param string $mode -
  274. *
  275. * @return int - Gets the block size, as an integer.
  276. */
  277. <<__Native>>
  278. function mcrypt_get_block_size(string $cipher,
  279. string $mode): mixed;
  280. /**
  281. * Gets the name of the specified cipher
  282. *
  283. * @param string $cipher -
  284. *
  285. * @return string - This function returns the name of the cipher or FALSE
  286. * if the cipher does not exist.
  287. */
  288. <<__Native>>
  289. function mcrypt_get_cipher_name(string $cipher): mixed;
  290. /**
  291. * Returns the size of the IV belonging to a specific cipher/mode combination
  292. *
  293. * @param string $cipher -
  294. * @param string $mode - The IV is ignored in ECB mode as this mode does
  295. * not require it. You will need to have the same IV (think: starting
  296. * point) both at encryption and decryption stages, otherwise your
  297. * encryption will fail.
  298. *
  299. * @return int - Returns the size of the Initialization Vector (IV) in
  300. * bytes. On error the function returns FALSE. If the IV is ignored in
  301. * the specified cipher/mode combination zero is returned.
  302. */
  303. <<__Native>>
  304. function mcrypt_get_iv_size(string $cipher,
  305. string $mode): mixed;
  306. /**
  307. * Gets the key size of the specified cipher
  308. *
  309. * @param string $cipher -
  310. * @param string $mode -
  311. *
  312. * @return int - Returns the maximum supported key size of the algorithm
  313. * in bytes .
  314. */
  315. <<__Native>>
  316. function mcrypt_get_key_size(string $cipher,
  317. string $mode): mixed;
  318. /**
  319. * Gets an array of all supported ciphers
  320. *
  321. * @param string $lib_dir - Specifies the directory where all algorithms
  322. * are located. If not specified, the value of the mcrypt.algorithms_dir
  323. * directive is used.
  324. *
  325. * @return array - Returns an array with all the supported algorithms.
  326. */
  327. <<__Native>>
  328. function mcrypt_list_algorithms(string $lib_dir = ''): varray;
  329. /**
  330. * Gets an array of all supported modes
  331. *
  332. * @param string $lib_dir - Specifies the directory where all modes are
  333. * located. If not specified, the value of the mcrypt.modes_dir directive
  334. * is used.
  335. *
  336. * @return array - Returns an array with all the supported modes.
  337. */
  338. <<__Native>>
  339. function mcrypt_list_modes(string $lib_dir = ''): varray;
  340. /**
  341. * Closes the mcrypt module
  342. *
  343. * @param resource $td - The encryption descriptor.
  344. *
  345. * @return bool -
  346. */
  347. <<__Native>>
  348. function mcrypt_module_close(resource $td): bool;
  349. /**
  350. * Returns the blocksize of the specified algorithm
  351. *
  352. * @param string $algorithm - The algorithm name.
  353. * @param string $lib_dir - This optional parameter can contain the
  354. * location where the mode module is on the system.
  355. *
  356. * @return int - Returns the block size of the algorithm specified in
  357. * bytes.
  358. */
  359. <<__Native>>
  360. function mcrypt_module_get_algo_block_size(string $algorithm,
  361. string $lib_dir = ''): int;
  362. /**
  363. * Returns the maximum supported keysize of the opened mode
  364. *
  365. * @param string $algorithm - The algorithm name.
  366. * @param string $lib_dir - This optional parameter can contain the
  367. * location where the mode module is on the system.
  368. *
  369. * @return int - This function returns the maximum supported key size of
  370. * the algorithm specified in bytes.
  371. */
  372. <<__Native>>
  373. function mcrypt_module_get_algo_key_size(string $algorithm,
  374. string $lib_dir = ''): int;
  375. /**
  376. * Returns an array with the supported keysizes of the opened algorithm
  377. *
  378. * @param string $algorithm - The algorithm to be used.
  379. * @param string $lib_dir - The optional lib_dir parameter can contain
  380. * the location where the algorithm module is on the system.
  381. *
  382. * @return array - Returns an array with the key sizes supported by the
  383. * specified algorithm. If it returns an empty array then all key sizes
  384. * between 1 and mcrypt_module_get_algo_key_size() are supported by the
  385. * algorithm.
  386. */
  387. <<__Native>>
  388. function mcrypt_module_get_supported_key_sizes(string $algorithm,
  389. string $lib_dir = ''): varray;
  390. /**
  391. * Returns if the specified module is a block algorithm or not
  392. *
  393. * @param string $mode - The mode to check.
  394. * @param string $lib_dir - The optional lib_dir parameter can contain
  395. * the location where the algorithm module is on the system.
  396. *
  397. * @return bool - This function returns TRUE if the mode is for use with
  398. * block algorithms, otherwise it returns FALSE. (e.g. FALSE for stream,
  399. * and TRUE for cbc, cfb, ofb).
  400. */
  401. <<__Native>>
  402. function mcrypt_module_is_block_algorithm_mode(string $mode,
  403. string $lib_dir= ''): bool;
  404. /**
  405. * This function checks whether the specified algorithm is a block algorithm
  406. *
  407. * @param string $algorithm - The algorithm to check.
  408. * @param string $lib_dir - The optional lib_dir parameter can contain
  409. * the location where the algorithm module is on the system.
  410. *
  411. * @return bool - This function returns TRUE if the specified algorithm
  412. * is a block algorithm, or FALSE if it is a stream one.
  413. */
  414. <<__Native>>
  415. function mcrypt_module_is_block_algorithm(string $algorithm,
  416. string $lib_dir= ''): bool;
  417. /**
  418. * Returns if the specified mode outputs blocks or not
  419. *
  420. * @param string $mode -
  421. * @param string $lib_dir - The optional lib_dir parameter can contain
  422. * the location where the algorithm module is on the system.
  423. *
  424. * @return bool - This function returns TRUE if the mode outputs blocks
  425. * of bytes or FALSE if it outputs just bytes. (e.g. TRUE for cbc and
  426. * ecb, and FALSE for cfb and stream).
  427. */
  428. <<__Native>>
  429. function mcrypt_module_is_block_mode(string $mode,
  430. string $lib_dir= ''): bool;
  431. /**
  432. * Opens the module of the algorithm and the mode to be used
  433. *
  434. * @param string $algorithm -
  435. * @param string $algorithm_directory - The algorithm_directory parameter
  436. * is used to locate the encryption module. When you supply a directory
  437. * name, it is used. When you set it to an empty string (""), the value
  438. * set by the mcrypt.algorithms_dir directive is used. When it is not
  439. * set, the default directory that is used is the one that was compiled
  440. * into libmcrypt (usually /usr/local/lib/libmcrypt).
  441. * @param string $mode -
  442. * @param string $mode_directory - The mode_directory parameter is used
  443. * to locate the encryption module. When you supply a directory name, it
  444. * is used. When you set it to an empty string (""), the value set by the
  445. * mcrypt.modes_dir directive is used. When it is not set, the default
  446. * directory that is used is the one that was compiled-in into libmcrypt
  447. * (usually /usr/local/lib/libmcrypt).
  448. *
  449. * @return resource - Normally it returns an encryption descriptor, or
  450. * FALSE on error.
  451. */
  452. <<__Native>>
  453. function mcrypt_module_open(string $algorithm,
  454. string $algorithm_directory,
  455. string $mode,
  456. string $mode_directory): mixed;
  457. /**
  458. * This function runs a self test on the specified module
  459. *
  460. * @param string $algorithm -
  461. * @param string $lib_dir - The optional lib_dir parameter can contain
  462. * the location where the algorithm module is on the system.
  463. *
  464. * @return bool - The function returns TRUE if the self test succeeds, or
  465. * FALSE when it fails.
  466. */
  467. <<__Native>>
  468. function mcrypt_module_self_test(string $algorithm,
  469. string $lib_dir = ''): bool;
  470. /**
  471. * Encrypts/decrypts data in OFB mode
  472. *
  473. * @param string $cipher -
  474. * @param string $key -
  475. * @param string $data -
  476. * @param int $mode -
  477. * @param string $iv -
  478. *
  479. * @return string -
  480. */
  481. <<__Native>>
  482. function mcrypt_ofb(string $cipher,
  483. string $key,
  484. string $data,
  485. mixed $mode,
  486. ?string $iv = null): mixed;
  487. /**
  488. * Decrypts data
  489. *
  490. * @param resource $td - An encryption descriptor returned by
  491. * mcrypt_module_open()
  492. * @param string $data - Encrypted data.
  493. *
  494. * @return string -
  495. */
  496. <<__Native>>
  497. function mdecrypt_generic(resource $td,
  498. string $data): mixed;