fips.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2017. See AUTHORS.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package openssl
  15. /*
  16. #include <openssl/ssl.h>
  17. */
  18. import "C"
  19. import "runtime"
  20. // FIPSModeSet enables a FIPS 140-2 validated mode of operation.
  21. // https://wiki.openssl.org/index.php/FIPS_mode_set()
  22. func FIPSModeSet(mode bool) error {
  23. runtime.LockOSThread()
  24. defer runtime.UnlockOSThread()
  25. var r C.int
  26. if mode {
  27. r = C.FIPS_mode_set(1)
  28. } else {
  29. r = C.FIPS_mode_set(0)
  30. }
  31. if r != 1 {
  32. return errorFromErrorQueue()
  33. }
  34. return nil
  35. }