crypt.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* This file is part of libmissive.
  2. *
  3. * libmissive is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * libmissive is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with libmissive. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <string.h>
  17. #include "crypt.h"
  18. int
  19. nonce_update(Nonce current, const Nonce newer)
  20. {
  21. switch (sodium_compare(current, newer, sizeof(Nonce))) {
  22. case 1:
  23. memcpy(current, newer, sizeof(Nonce));
  24. /* fallthru */
  25. case 0:
  26. sodium_increment(current, sizeof(Nonce));
  27. return 0;
  28. case -1:
  29. break;
  30. }
  31. return -1;
  32. }
  33. void
  34. box_keys(Box_skey skey, Box_pkey pkey)
  35. {
  36. crypto_box_keypair(pkey, skey);
  37. }
  38. void
  39. sign_keys(Sign_skey skey, Sign_pkey pkey)
  40. {
  41. crypto_sign_keypair(pkey, skey);
  42. }