s2n_stream_cipher_null.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "crypto/s2n_cipher.h"
  16. #include "error/s2n_errno.h"
  17. #include "utils/s2n_blob.h"
  18. #include "utils/s2n_safety.h"
  19. static uint8_t s2n_stream_cipher_null_available()
  20. {
  21. return 1;
  22. }
  23. static int s2n_stream_cipher_null_endecrypt(struct s2n_session_key *key, struct s2n_blob *in, struct s2n_blob *out)
  24. {
  25. S2N_ERROR_IF(out->size < in->size, S2N_ERR_SIZE_MISMATCH);
  26. if (in->data != out->data) {
  27. POSIX_CHECKED_MEMCPY(out->data, in->data, out->size);
  28. }
  29. return 0;
  30. }
  31. static int s2n_stream_cipher_null_get_key(struct s2n_session_key *key, struct s2n_blob *in)
  32. {
  33. return 0;
  34. }
  35. static int s2n_stream_cipher_null_destroy_key(struct s2n_session_key *key)
  36. {
  37. return 0;
  38. }
  39. static int s2n_stream_cipher_null_init(struct s2n_session_key *key)
  40. {
  41. return 0;
  42. }
  43. const struct s2n_cipher s2n_null_cipher = {
  44. .type = S2N_STREAM,
  45. .key_material_size = 0,
  46. .io.stream = {
  47. .decrypt = s2n_stream_cipher_null_endecrypt,
  48. .encrypt = s2n_stream_cipher_null_endecrypt },
  49. .is_available = s2n_stream_cipher_null_available,
  50. .init = s2n_stream_cipher_null_init,
  51. .set_encryption_key = s2n_stream_cipher_null_get_key,
  52. .set_decryption_key = s2n_stream_cipher_null_get_key,
  53. .destroy_key = s2n_stream_cipher_null_destroy_key,
  54. };