File libgcrypt-CVE-2015-0837-1.patch of Package libgcrypt.2574

commit 653a9fa1a3a4c35a4dc1841cb57d7e2a318f3288
Author: NIIBE Yutaka <gniibe@fsij.org>
Date:   Wed Feb 11 21:42:22 2015 +0900

    mpi: Add mpi_set_cond.
    
    * mpi/mpiutil.c (_gcry_mpi_set_cond): New.
    (_gcry_mpi_swap_cond): Fix types.
    * src/mpi.h (mpi_set_cond): New.

Index: libgcrypt-1.6.1/mpi/mpiutil.c
===================================================================
--- libgcrypt-1.6.1.orig/mpi/mpiutil.c	2015-08-14 14:36:23.391278412 +0200
+++ libgcrypt-1.6.1/mpi/mpiutil.c	2015-08-14 14:36:24.103288501 +0200
@@ -482,6 +482,31 @@ _gcry_mpi_set (gcry_mpi_t w, gcry_mpi_t
   return w;
 }
 
+gcry_mpi_t
+_gcry_mpi_set_cond (gcry_mpi_t w, const gcry_mpi_t u, unsigned long set)
+{
+  mpi_size_t i;
+  mpi_size_t nlimbs = u->alloced;
+  mpi_limb_t mask = ((mpi_limb_t)0) - !!set;
+  mpi_limb_t x;
+
+  if (w->alloced != u->alloced)
+    log_bug ("mpi_set_cond: different sizes\n");
+
+  for (i = 0; i < nlimbs; i++)
+    {
+      x = mask & (w->d[i] ^ u->d[i]);
+      w->d[i] = w->d[i] ^ x;
+    }
+
+  x = mask & (w->nlimbs ^ u->nlimbs);
+  w->nlimbs = w->nlimbs ^ x;
+
+  x = mask & (w->sign ^ u->sign);
+  w->sign = w->sign ^ x;
+  return w;
+}
+
 
 gcry_mpi_t
 _gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u)
Index: libgcrypt-1.6.1/src/mpi.h
===================================================================
--- libgcrypt-1.6.1.orig/src/mpi.h	2015-08-14 14:36:24.103288501 +0200
+++ libgcrypt-1.6.1/src/mpi.h	2015-08-14 14:41:29.211610209 +0200
@@ -119,8 +119,11 @@ void _gcry_mpi_immutable_failed (void);
 #define mpi_alloc_set_ui(a)   _gcry_mpi_alloc_set_ui ((a))
 #define mpi_m_check(a)        _gcry_mpi_m_check ((a))
 #define mpi_const(n)          _gcry_mpi_const ((n))
+#define mpi_set_cond(w,u,set)  _gcry_mpi_set_cond ((w),(u),(set))
 
 void _gcry_mpi_clear( gcry_mpi_t a );
+gcry_mpi_t _gcry_mpi_set_cond (gcry_mpi_t w, const gcry_mpi_t u,
+                               unsigned long swap);
 gcry_mpi_t  _gcry_mpi_alloc_like( gcry_mpi_t a );
 gcry_mpi_t  _gcry_mpi_alloc_set_ui( unsigned long u);
 void _gcry_mpi_m_check( gcry_mpi_t a );