fspr_random.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_RANDOM_H
  17. #define APR_RANDOM_H
  18. #include <fspr_pools.h>
  19. typedef struct fspr_crypto_hash_t fspr_crypto_hash_t;
  20. typedef void fspr_crypto_hash_init_t(fspr_crypto_hash_t *hash);
  21. typedef void fspr_crypto_hash_add_t(fspr_crypto_hash_t *hash,const void *data,
  22. fspr_size_t bytes);
  23. typedef void fspr_crypto_hash_finish_t(fspr_crypto_hash_t *hash,
  24. unsigned char *result);
  25. /* FIXME: make this opaque */
  26. struct fspr_crypto_hash_t {
  27. fspr_crypto_hash_init_t *init;
  28. fspr_crypto_hash_add_t *add;
  29. fspr_crypto_hash_finish_t *finish;
  30. fspr_size_t size;
  31. void *data;
  32. };
  33. APR_DECLARE(fspr_crypto_hash_t *) fspr_crypto_sha256_new(fspr_pool_t *p);
  34. typedef struct fspr_random_t fspr_random_t;
  35. APR_DECLARE(void) fspr_random_init(fspr_random_t *g,fspr_pool_t *p,
  36. fspr_crypto_hash_t *pool_hash,
  37. fspr_crypto_hash_t *key_hash,
  38. fspr_crypto_hash_t *prng_hash);
  39. APR_DECLARE(fspr_random_t *) fspr_random_standard_new(fspr_pool_t *p);
  40. APR_DECLARE(void) fspr_random_add_entropy(fspr_random_t *g,
  41. const void *entropy_,
  42. fspr_size_t bytes);
  43. APR_DECLARE(fspr_status_t) fspr_random_insecure_bytes(fspr_random_t *g,
  44. void *random,
  45. fspr_size_t bytes);
  46. APR_DECLARE(fspr_status_t) fspr_random_secure_bytes(fspr_random_t *g,
  47. void *random,
  48. fspr_size_t bytes);
  49. APR_DECLARE(void) fspr_random_barrier(fspr_random_t *g);
  50. APR_DECLARE(fspr_status_t) fspr_random_secure_ready(fspr_random_t *r);
  51. APR_DECLARE(fspr_status_t) fspr_random_insecure_ready(fspr_random_t *r);
  52. /* Call this in the child after forking to mix the randomness
  53. pools. Note that its generally a bad idea to fork a process with a
  54. real PRNG in it - better to have the PRNG externally and get the
  55. randomness from there. However, if you really must do it, then you
  56. should supply all your entropy to all the PRNGs - don't worry, they
  57. won't produce the same output.
  58. Note that fspr_proc_fork() calls this for you, so only weird
  59. applications need ever call it themselves.
  60. */
  61. struct fspr_proc_t;
  62. APR_DECLARE(void) fspr_random_after_fork(struct fspr_proc_t *proc);
  63. #endif /* ndef APR_RANDOM_H */