2
0

apr_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 <apr_pools.h>
  19. typedef struct apr_crypto_hash_t apr_crypto_hash_t;
  20. typedef void apr_crypto_hash_init_t(apr_crypto_hash_t *hash);
  21. typedef void apr_crypto_hash_add_t(apr_crypto_hash_t *hash,const void *data,
  22. apr_size_t bytes);
  23. typedef void apr_crypto_hash_finish_t(apr_crypto_hash_t *hash,
  24. unsigned char *result);
  25. /* FIXME: make this opaque */
  26. struct apr_crypto_hash_t {
  27. apr_crypto_hash_init_t *init;
  28. apr_crypto_hash_add_t *add;
  29. apr_crypto_hash_finish_t *finish;
  30. apr_size_t size;
  31. void *data;
  32. };
  33. APR_DECLARE(apr_crypto_hash_t *) apr_crypto_sha256_new(apr_pool_t *p);
  34. typedef struct apr_random_t apr_random_t;
  35. APR_DECLARE(void) apr_random_init(apr_random_t *g,apr_pool_t *p,
  36. apr_crypto_hash_t *pool_hash,
  37. apr_crypto_hash_t *key_hash,
  38. apr_crypto_hash_t *prng_hash);
  39. APR_DECLARE(apr_random_t *) apr_random_standard_new(apr_pool_t *p);
  40. APR_DECLARE(void) apr_random_add_entropy(apr_random_t *g,
  41. const void *entropy_,
  42. apr_size_t bytes);
  43. APR_DECLARE(apr_status_t) apr_random_insecure_bytes(apr_random_t *g,
  44. void *random,
  45. apr_size_t bytes);
  46. APR_DECLARE(apr_status_t) apr_random_secure_bytes(apr_random_t *g,
  47. void *random,
  48. apr_size_t bytes);
  49. APR_DECLARE(void) apr_random_barrier(apr_random_t *g);
  50. APR_DECLARE(apr_status_t) apr_random_secure_ready(apr_random_t *r);
  51. APR_DECLARE(apr_status_t) apr_random_insecure_ready(apr_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 apr_proc_fork() calls this for you, so only weird
  59. applications need ever call it themselves.
  60. */
  61. struct apr_proc_t;
  62. APR_DECLARE(void) apr_random_after_fork(struct apr_proc_t *proc);
  63. #endif /* ndef APR_RANDOM_H */