hmac.scm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ;;; guile-gcrypt --- crypto tooling for guile
  2. ;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
  3. ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of guile-gcrypt.
  6. ;;;
  7. ;;; guile-gcrypt is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or
  10. ;;; (at your option) any later version.
  11. ;;;
  12. ;;; guile-gcrypt is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ;;; General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with guile-gcrypt. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (test-mac)
  20. #:use-module (rnrs bytevectors)
  21. #:use-module (srfi srfi-64)
  22. #:use-module (gcrypt hmac)) ;the deprecated module
  23. (test-begin "hmac")
  24. (define test-key (gen-signing-key))
  25. (let ((sig (sign-data test-key "monkey party"
  26. #:algorithm 'sha256)))
  27. ;; Should be a bytevector
  28. (test-assert (bytevector? sig))
  29. ;; Correct sig succeeds
  30. (test-assert (verify-sig test-key "monkey party" sig
  31. #:algorithm 'sha256)))
  32. (let ((sig (sign-data test-key "monkey party")))
  33. ;; Should be a bytevector
  34. (test-assert (bytevector? sig))
  35. ;; Correct sig succeeds
  36. (test-assert (verify-sig test-key "monkey party" sig)))
  37. (test-end "hmac")