compat_dh.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* 32-bit compatibility syscall for 64-bit systems for DH operations
  3. *
  4. * Copyright (C) 2016 Stephan Mueller <smueller@chronox.de>
  5. */
  6. #include <linux/uaccess.h>
  7. #include "internal.h"
  8. /*
  9. * Perform the DH computation or DH based key derivation.
  10. *
  11. * If successful, 0 will be returned.
  12. */
  13. long compat_keyctl_dh_compute(struct keyctl_dh_params __user *params,
  14. char __user *buffer, size_t buflen,
  15. struct compat_keyctl_kdf_params __user *kdf)
  16. {
  17. struct keyctl_kdf_params kdfcopy;
  18. struct compat_keyctl_kdf_params compat_kdfcopy;
  19. if (!kdf)
  20. return __keyctl_dh_compute(params, buffer, buflen, NULL);
  21. if (copy_from_user(&compat_kdfcopy, kdf, sizeof(compat_kdfcopy)) != 0)
  22. return -EFAULT;
  23. kdfcopy.hashname = compat_ptr(compat_kdfcopy.hashname);
  24. kdfcopy.otherinfo = compat_ptr(compat_kdfcopy.otherinfo);
  25. kdfcopy.otherinfolen = compat_kdfcopy.otherinfolen;
  26. memcpy(kdfcopy.__spare, compat_kdfcopy.__spare,
  27. sizeof(kdfcopy.__spare));
  28. return __keyctl_dh_compute(params, buffer, buflen, &kdfcopy);
  29. }