s2n_mem.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #pragma once
  16. #include <stdint.h>
  17. #include "utils/s2n_blob.h"
  18. int s2n_mem_init(void);
  19. bool s2n_mem_is_init(void);
  20. uint32_t s2n_mem_get_page_size(void);
  21. int s2n_mem_cleanup(void);
  22. /*
  23. * Generally, s2n_realloc is preferred over s2n_alloc. This is because calling
  24. * s2n_alloc on a blob that already has memory allocated will leak memory.
  25. */
  26. int s2n_alloc(struct s2n_blob *b, uint32_t size);
  27. int s2n_realloc(struct s2n_blob *b, uint32_t size);
  28. int s2n_free(struct s2n_blob *b);
  29. int s2n_free_without_wipe(struct s2n_blob *b);
  30. int s2n_free_object(uint8_t **p_data, uint32_t size);
  31. int s2n_dup(struct s2n_blob *from, struct s2n_blob *to);
  32. /* Unlike free, s2n_free_or_wipe accepts static blobs.
  33. * It frees allocated blobs and wipes static blobs.
  34. *
  35. * This is mostly useful for some of the s2n-tls shared secret generation logic,
  36. * which allocates memory for some algorithms and uses static memory for others.
  37. *
  38. * Prefer s2n_free. Only use this method if completely necessary.
  39. */
  40. int s2n_free_or_wipe(struct s2n_blob *b);