compat_dh.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* 32-bit compatibility syscall for 64-bit systems for DH operations
  2. *
  3. * Copyright (C) 2016 Stephan Mueller <smueller@chronox.de>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. #include <linux/uaccess.h>
  11. #include "internal.h"
  12. /*
  13. * Perform the DH computation or DH based key derivation.
  14. *
  15. * If successful, 0 will be returned.
  16. */
  17. long compat_keyctl_dh_compute(struct keyctl_dh_params __user *params,
  18. char __user *buffer, size_t buflen,
  19. struct compat_keyctl_kdf_params __user *kdf)
  20. {
  21. struct keyctl_kdf_params kdfcopy;
  22. struct compat_keyctl_kdf_params compat_kdfcopy;
  23. if (!kdf)
  24. return __keyctl_dh_compute(params, buffer, buflen, NULL);
  25. if (copy_from_user(&compat_kdfcopy, kdf, sizeof(compat_kdfcopy)) != 0)
  26. return -EFAULT;
  27. kdfcopy.hashname = compat_ptr(compat_kdfcopy.hashname);
  28. kdfcopy.otherinfo = compat_ptr(compat_kdfcopy.otherinfo);
  29. kdfcopy.otherinfolen = compat_kdfcopy.otherinfolen;
  30. memcpy(kdfcopy.__spare, compat_kdfcopy.__spare,
  31. sizeof(kdfcopy.__spare));
  32. return __keyctl_dh_compute(params, buffer, buflen, &kdfcopy);
  33. }