Skip to contentSkip to conversation

evm: digital signature verification extension

PATCH In review Dmitry Kasatkin 5 participants 20 messages Oct 19, 2011 – Mar 22, 2012

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover evm: digital signature verification extension

Hello,

Changes in version 2.2:
* uses EXPORT_SYMBOL_GPL
* disabled code removed
* removed casting after kmalloc

Changes to version 2.1:
* MPI lib moved to /lib directory.
* added configuration option CONFIG_MPILIB_EXTRA to exclude building a part of MPI library, which is not used in RSA impelementation.
* added API documentation
* added Documentation for digsig
* splitted evm digital signature verification patch into 2. Common code will be used by IMA digital singnature verification.

Changes to version 2.0:
* MPI patch has been split to smaller in order to go to mailing lists. First 2 patches include only source and header files which are needed to build ksign verification. Headers and sources are split just to meet 100k kernel.org limit.
Last patch adds all rest soures from original ported MPI library.

Changes to version 1.1:
* GnuPG MPI library has been refactored with lindent and checkpatch errors and warnings has been fixed.
* creation of evm keyring has been remove. It is done now in user space.
* related ksign and evm patches has been squashed.
* patch descriptions has been updated.

As EVM patches were recently merged to security-testing-2.6#next, it is a good time to resend evm signature verification patches for active discussion. Last time I forgot --cc linux-crypto. Here it is.

This patchset introduces digital signature extensions for the IMA/EVM kernel integrity subsystem and is applied on the top of the EVM patches posted to LSM mailing list earlier.

Currently EVM stores the HMAC in security.evm to verify integrity of the file's metadata. This is quite sufficient for individually installed systems, where a system unique HMAC key can be provisioned and the initial filesystem labeling can be done.

Software installation for consumer electronics or embedded devices is usually done via flashing a filesystem image. Initial filesystem image labeling is done during image creation process. It either has to be done (1) using a system unique HMAC key or (2) using an image specific HMAC key. In first case, those keys are either unknown, or a unique image has to be created for thousand or millions of devices, which is not feasible. The second case, using an image specific HMAC key, would require (2.1) provisioning of the key to millions of devices, which is not easily feasible or (2.1) encrypting the key with a shared symmetric key which is not a strong security measure.

Digital signature extension for EVM provides a solution to perform labeling of the image using a single digital private key and use a known public key to verify the signature. For performance reasons, after verification, signature is replaced with local HMAC.

Digital signature verification uses RSA algorithm, implemented using cut-down port of multi-precision integers (MPI) library from GnuPG and has been taken from RedHat Enterprise Linux kernel (MODSIGN patches). Decision to use this library was made, because its performance was 2 times better than other ports such as libtommath library.

The GnuPG MPI library patch was posted here on linux-crypto back in
http://www.mail-archive.com/[email protected]/msg05613.html.
Reason for upstreaming was that it to be a solid in-kernel user of the API. Now with the recent merging of the EVM patches in linux-next via security-testing-2.6/#next, MPI library is required for EVM digital signature verification extension.

The motivation for integrity protection, in general, is to protect against offline modifications. The runtime protection is ensured via access control mechanisms. Of particular importance is protecting users or owners from being sold or given tampered devices, which can do nasty things such as spying or stealing personal data. Integrity protection ensures that modifications of the system will not remain undetected. The EVM digital signature extension makes this feasible for consumerelectronics/embedded devices.

There is also a second patchset which implements digital signature support for IMA-appraisal patchset, which is planned to be reviewed right after the IMA-appaisal review.

All patches on the top of ima-2.6 (3.x.x) kernel are available here:
git://git.kernel.org/pub/scm/linux/kernel/git/kasatkin/ima-ksign.git
http://meego.gitorious.org/meego-platform-security/ima-ksign

Supporting utility for key handling and signing is available here:
http://meego.gitorious.org/meego-platform-security/evm-utils

Regards,
Dmitry

Dmitry Kasatkin (7):
crypto: GnuPG based MPI lib - source files (part 1)
crypto: GnuPG based MPI lib - header files (part 2)
crypto: GnuPG based MPI lib - make files (part 3)
crypto: GnuPG based MPI lib - additional sources (part 4)
crypto: digital signature verification support
integrity: digital signature verification using multiple keyrings
evm: digital signature verification support

 Documentation/digsig.txt            |   97 +++
 include/linux/digsig.h              |   64 ++
 include/linux/mpi.h                 |  146 ++++
 lib/Kconfig                         |   25 +
 lib/Makefile                        |    3 +
 lib/digsig.c                        |  283 +++++++
 lib/mpi/Makefile                    |   33 +
 lib/mpi/generic_mpi-asm-defs.h      |    4 +
 lib/mpi/generic_mpih-add1.c         |   61 ++
 lib/mpi/generic_mpih-lshift.c       |   63 ++
 lib/mpi/generic_mpih-mul1.c         |   57 ++
 lib/mpi/generic_mpih-mul2.c         |   60 ++
 lib/mpi/generic_mpih-mul3.c         |   61 ++
 lib/mpi/generic_mpih-rshift.c       |   63 ++
 lib/mpi/generic_mpih-sub1.c         |   60 ++
 lib/mpi/longlong.h                  | 1478 +++++++++++++++++++++++++++++++++++
 lib/mpi/mpi-add.c                   |  234 ++++++
 lib/mpi/mpi-bit.c                   |  236 ++++++
 lib/mpi/mpi-cmp.c                   |   68 ++
 lib/mpi/mpi-div.c                   |  333 ++++++++
 lib/mpi/mpi-gcd.c                   |   59 ++
 lib/mpi/mpi-inline.c                |   31 +
 lib/mpi/mpi-inline.h                |  122 +++
 lib/mpi/mpi-internal.h              |  261 ++++++
 lib/mpi/mpi-inv.c                   |  187 +++++
 lib/mpi/mpi-mpow.c                  |  133 ++++
 lib/mpi/mpi-mul.c                   |  194 +++++
 lib/mpi/mpi-pow.c                   |  323 ++++++++
 lib/mpi/mpi-scan.c                  |  136 ++++
 lib/mpi/mpicoder.c                  |  365 +++++++++
 lib/mpi/mpih-cmp.c                  |   56 ++
 lib/mpi/mpih-div.c                  |  541 +++++++++++++
 lib/mpi/mpih-mul.c                  |  527 +++++++++++++
 lib/mpi/mpiutil.c                   |  208 +++++
 security/integrity/Kconfig          |   14 +
 security/integrity/Makefile         |    1 +
 security/integrity/digsig.c         |   48 ++
 security/integrity/evm/evm.h        |   12 +
 security/integrity/evm/evm_crypto.c |   66 ++-
 security/integrity/evm/evm_main.c   |   94 ++-
 security/integrity/integrity.h      |   20 +
 41 files changed, 6797 insertions(+), 30 deletions(-)
 create mode 100644 Documentation/digsig.txt
 create mode 100644 include/linux/digsig.h
 create mode 100644 include/linux/mpi.h
 create mode 100644 lib/digsig.c
 create mode 100644 lib/mpi/Makefile
 create mode 100644 lib/mpi/generic_mpi-asm-defs.h
 create mode 100644 lib/mpi/generic_mpih-add1.c
 create mode 100644 lib/mpi/generic_mpih-lshift.c
 create mode 100644 lib/mpi/generic_mpih-mul1.c
 create mode 100644 lib/mpi/generic_mpih-mul2.c
 create mode 100644 lib/mpi/generic_mpih-mul3.c
 create mode 100644 lib/mpi/generic_mpih-rshift.c
 create mode 100644 lib/mpi/generic_mpih-sub1.c
 create mode 100644 lib/mpi/longlong.h
 create mode 100644 lib/mpi/mpi-add.c
 create mode 100644 lib/mpi/mpi-bit.c
 create mode 100644 lib/mpi/mpi-cmp.c
 create mode 100644 lib/mpi/mpi-div.c
 create mode 100644 lib/mpi/mpi-gcd.c
 create mode 100644 lib/mpi/mpi-inline.c
 create mode 100644 lib/mpi/mpi-inline.h
 create mode 100644 lib/mpi/mpi-internal.h
 create mode 100644 lib/mpi/mpi-inv.c
 create mode 100644 lib/mpi/mpi-mpow.c
 create mode 100644 lib/mpi/mpi-mul.c
 create mode 100644 lib/mpi/mpi-pow.c
 create mode 100644 lib/mpi/mpi-scan.c
 create mode 100644 lib/mpi/mpicoder.c
 create mode 100644 lib/mpi/mpih-cmp.c
 create mode 100644 lib/mpi/mpih-div.c
 create mode 100644 lib/mpi/mpih-mul.c
 create mode 100644 lib/mpi/mpiutil.c
 create mode 100644 security/integrity/digsig.c
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/7 crypto: GnuPG based MPI lib - source files (part 1)

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

Due to patch size limitation, the patch is divided into 4 parts.

---
 lib/mpi/generic_mpih-add1.c   |   61 +++++
 lib/mpi/generic_mpih-lshift.c |   63 +++++
 lib/mpi/generic_mpih-mul1.c   |   57 +++++
 lib/mpi/generic_mpih-mul2.c   |   60 +++++
 lib/mpi/generic_mpih-mul3.c   |   61 +++++
 lib/mpi/generic_mpih-rshift.c |   63 +++++
 lib/mpi/generic_mpih-sub1.c   |   60 +++++
 lib/mpi/mpi-bit.c             |  236 ++++++++++++++++++
 lib/mpi/mpi-pow.c             |  323 ++++++++++++++++++++++++
 lib/mpi/mpicoder.c            |  365 +++++++++++++++++++++++++++
 lib/mpi/mpih-cmp.c            |   56 +++++
 lib/mpi/mpih-div.c            |  541 +++++++++++++++++++++++++++++++++++++++++
 lib/mpi/mpih-mul.c            |  527 +++++++++++++++++++++++++++++++++++++++
 lib/mpi/mpiutil.c             |  208 ++++++++++++++++
 14 files changed, 2681 insertions(+), 0 deletions(-)
 create mode 100644 lib/mpi/generic_mpih-add1.c
 create mode 100644 lib/mpi/generic_mpih-lshift.c
 create mode 100644 lib/mpi/generic_mpih-mul1.c
 create mode 100644 lib/mpi/generic_mpih-mul2.c
 create mode 100644 lib/mpi/generic_mpih-mul3.c
 create mode 100644 lib/mpi/generic_mpih-rshift.c
 create mode 100644 lib/mpi/generic_mpih-sub1.c
 create mode 100644 lib/mpi/mpi-bit.c
 create mode 100644 lib/mpi/mpi-pow.c
 create mode 100644 lib/mpi/mpicoder.c
 create mode 100644 lib/mpi/mpih-cmp.c
 create mode 100644 lib/mpi/mpih-div.c
 create mode 100644 lib/mpi/mpih-mul.c
 create mode 100644 lib/mpi/mpiutil.c
lib/mpi/generic_mpih-add1.c new file +61 -0
new file mode 100644
index 0000000..c94c7dd
@@ -0,0 +1,61 @@
+/* mpihelp-add_1.c  -  MPI helper functions
+ * Copyright (C) 1994, 1996, 1997, 1998,
+ *               2000 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * Note: This code is heavily based on the GNU MP Library.
+ *	 Actually it's the same code with only minor changes in the
+ *	 way the data is stored; this is to support the abstraction
+ *	 of an optional secure memory allocation which may be used
+ *	 to avoid revealing of sensitive data due to paging etc.
+ *	 The GNU MP Library itself is published under the LGPL;
+ *	 however I decided to publish this code under the plain GPL.
+ */
+
+#include "mpi-internal.h"
+#include "longlong.h"
+
+mpi_limb_t
+mpihelp_add_n(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
+	      mpi_ptr_t s2_ptr, mpi_size_t size)
+{
+	mpi_limb_t x, y, cy;
+	mpi_size_t j;
+
+	/* The loop counter and index J goes from -SIZE to -1.  This way
+	   the loop becomes faster.  */
+	j = -size;
+
+	/* Offset the base pointers to compensate for the negative indices. */
+	s1_ptr -= j;
+	s2_ptr -= j;
+	res_ptr -= j;
+
+	cy = 0;
+	do {
+		y = s2_ptr[j];
+		x = s1_ptr[j];
+		y += cy;	/* add previous carry to one addend */
+		cy = y < cy;	/* get out carry from that addition */
+		y += x;		/* add other addend */
+		cy += y < x;	/* get out carry from that add, combine */
+		res_ptr[j] = y;
+	} while (++j);
+
+	return cy;
+}
lib/mpi/generic_mpih-lshift.c new file +63 -0

63 lines not on this page · raw message

lib/mpi/generic_mpih-mul1.c new file +57 -0

57 lines not on this page · raw message

lib/mpi/generic_mpih-mul2.c new file +60 -0

60 lines not on this page · raw message

lib/mpi/generic_mpih-mul3.c new file +61 -0

61 lines not on this page · raw message

lib/mpi/generic_mpih-rshift.c new file +63 -0

63 lines not on this page · raw message

lib/mpi/generic_mpih-sub1.c new file +60 -0

60 lines not on this page · raw message

lib/mpi/mpi-bit.c new file +236 -0

236 lines not on this page · raw message

lib/mpi/mpi-pow.c new file +323 -0

323 lines not on this page · raw message

lib/mpi/mpicoder.c new file +365 -0

365 lines not on this page · raw message

lib/mpi/mpih-cmp.c new file +56 -0

56 lines not on this page · raw message

lib/mpi/mpih-div.c new file +541 -0

541 lines not on this page · raw message

lib/mpi/mpih-mul.c new file +527 -0

527 lines not on this page · raw message

lib/mpi/mpiutil.c new file +208 -0

208 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#2 lore raw

Re: [PATCH v2.2 1/7] crypto: GnuPG based MPI lib - source files (part 1)

Hi all,

Quoted 10 lines · On Wed, 19 Oct 2011 14:51:30 +0300 Dmitry Kasatkin <[email protected]>…

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

Due to patch size limitation, the patch is divided into 4 parts.

I just noticed that this has been added to the "next" branch of the security tree (and thus into the next release of linux-next). I think that these patches should be rearranged as in their current form, they break bisection (since the files in this patch reference include files in
a latter patch). We generally prefer large patches to be broken up into
logical sub patches rather than just along file boundaries.

In this case, even though it was broken up for review, it could have been committed as one large commit (assuming that there is no sensible way to break it up).

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#3 lore raw

Re: [PATCH v2.2 1/7] crypto: GnuPG based MPI lib - source files (part 1)

Quoted 21 lines · Stephen Rothwell

Hi all,

Quoted 10 lines · On Wed, 19 Oct 2011 14:51:30 +0300 Dmitry Kasatkin <[email protected]>…

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

Due to patch size limitation, the patch is divided into 4 parts.

I just noticed that this has been added to the "next" branch of the security tree (and thus into the next release of linux-next).  I think that these patches should be rearranged as in their current form, they break bisection (since the files in this patch reference include files in a latter patch).   We generally prefer large patches to be broken up into logical sub patches rather than just along file boundaries.

Quoted 3 lines

In this case, even though it was broken up for review, it could have been committed as one large commit (assuming that there is no sensible way to break it up).

Hi,

It can be easily split into 2 commits and one of them would not comply with mailing list limits.

James, should I do anything about it?

Thanks,

- Dmitry

Quoted 5 lines

--
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/

maintainer
#4 lore raw

Re: [PATCH v2.2 1/7] crypto: GnuPG based MPI lib - source files (part 1)

Quoted 4 lines · Dmitry

It can be easily split into 2 commits and one of them would not comply with mailing list limits.

James, should I do anything about it?

No, it's in my public tree now.

- James

Signature · 2 lines
James Morris
<[email protected]>
#5 lore raw

Re: [PATCH v2.2 1/7] crypto: GnuPG based MPI lib - source files (part 1)

Quoted 9 lines · James Morris
Quoted 4 lines · Dmitry

It can be easily split into 2 commits and one of them would not comply with mailing list limits.

James, should I do anything about it?

No, it's in my public tree now.

Ok.

In fact it does not break bisect, because compilation is enabled in the 3rd patch.

BR,
Dmitry

Quoted 6 lines

- James
--
James Morris
<[email protected]>

#6 lore raw

Re: [PATCH v2.2 1/7] crypto: GnuPG based MPI lib - source files (part 1)

Hi Dmitry,

Quoted 3 lines · Dmitry

In fact it does not break bisect, because compilation is enabled in the 3rd patch.

Ah. sorry, I missed that.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#7 lore raw

PATCH 2/7 crypto: GnuPG based MPI lib - header files (part 2)

In reply to Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

Due to patch size limitation, the patch is divided into 4 parts.

---
 include/linux/mpi.h    |  146 +++++
 lib/mpi/longlong.h     | 1478 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/mpi/mpi-inline.h   |  122 ++++
 lib/mpi/mpi-internal.h |  261 +++++++++
 4 files changed, 2007 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/mpi.h
 create mode 100644 lib/mpi/longlong.h
 create mode 100644 lib/mpi/mpi-inline.h
 create mode 100644 lib/mpi/mpi-internal.h
include/linux/mpi.h new file +146 -0
new file mode 100644
index 0000000..06f8899
@@ -0,0 +1,146 @@
+/* mpi.h  -  Multi Precision Integers
+ *	Copyright (C) 1994, 1996, 1998, 1999,
+ *                    2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GNUPG.
+ *
+ * GNUPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * Note: This code is heavily based on the GNU MP Library.
+ *	 Actually it's the same code with only minor changes in the
+ *	 way the data is stored; this is to support the abstraction
+ *	 of an optional secure memory allocation which may be used
+ *	 to avoid revealing of sensitive data due to paging etc.
+ *	 The GNU MP Library itself is published under the LGPL;
+ *	 however I decided to publish this code under the plain GPL.
+ */
+
+#ifndef G10_MPI_H
+#define G10_MPI_H
+
+#include <linux/types.h>
+
+/* DSI defines */
+
+#define SHA1_DIGEST_LENGTH   20
+
+/*end of DSI defines */
+
+#define BYTES_PER_MPI_LIMB	(BITS_PER_LONG / 8)
+#define BITS_PER_MPI_LIMB	BITS_PER_LONG
+
+typedef unsigned long int mpi_limb_t;
+typedef signed long int mpi_limb_signed_t;
+
+struct gcry_mpi {
+	int alloced;		/* array size (# of allocated limbs) */
+	int nlimbs;		/* number of valid limbs */
+	int nbits;		/* the real number of valid bits (info only) */
+	int sign;		/* indicates a negative number */
+	unsigned flags;		/* bit 0: array must be allocated in secure memory space */
+	/* bit 1: not used */
+	/* bit 2: the limb is a pointer to some m_alloced data */
+	mpi_limb_t *d;		/* array with the limbs */
+};
+
+typedef struct gcry_mpi *MPI;
+
+#define MPI_NULL NULL
+
+#define mpi_get_nlimbs(a)     ((a)->nlimbs)
+#define mpi_is_neg(a)	      ((a)->sign)
+
+/*-- mpiutil.c --*/
+MPI mpi_alloc(unsigned nlimbs);
+MPI mpi_alloc_secure(unsigned nlimbs);
+MPI mpi_alloc_like(MPI a);
+void mpi_free(MPI a);
+int mpi_resize(MPI a, unsigned nlimbs);
+int mpi_copy(MPI *copy, const MPI a);
+void mpi_clear(MPI a);
+int mpi_set(MPI w, MPI u);
+int mpi_set_ui(MPI w, ulong u);
+MPI mpi_alloc_set_ui(unsigned long u);
+void mpi_m_check(MPI a);
+void mpi_swap(MPI a, MPI b);
+
+/*-- mpicoder.c --*/
+MPI do_encode_md(const void *sha_buffer, unsigned nbits);
+MPI mpi_read_from_buffer(const void *buffer, unsigned *ret_nread);
+int mpi_fromstr(MPI val, const char *str);
+u32 mpi_get_keyid(MPI a, u32 *keyid);
+void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign);
+void *mpi_get_secure_buffer(MPI a, unsigned *nbytes, int *sign);
+int mpi_set_buffer(MPI a, const void *buffer, unsigned nbytes, int sign);
+
+#define log_mpidump g10_log_mpidump
+
+/*-- mpi-add.c --*/
+int mpi_add_ui(MPI w, MPI u, ulong v);
+int mpi_add(MPI w, MPI u, MPI v);
+int mpi_addm(MPI w, MPI u, MPI v, MPI m);
+int mpi_sub_ui(MPI w, MPI u, ulong v);
+int mpi_sub(MPI w, MPI u, MPI v);
+int mpi_subm(MPI w, MPI u, MPI v, MPI m);
+
+/*-- mpi-mul.c --*/
+int mpi_mul_ui(MPI w, MPI u, ulong v);
+int mpi_mul_2exp(MPI w, MPI u, ulong cnt);
+int mpi_mul(MPI w, MPI u, MPI v);
+int mpi_mulm(MPI w, MPI u, MPI v, MPI m);
+
+/*-- mpi-div.c --*/
+ulong mpi_fdiv_r_ui(MPI rem, MPI dividend, ulong divisor);
+int mpi_fdiv_r(MPI rem, MPI dividend, MPI divisor);
+int mpi_fdiv_q(MPI quot, MPI dividend, MPI divisor);
+int mpi_fdiv_qr(MPI quot, MPI rem, MPI dividend, MPI divisor);
+int mpi_tdiv_r(MPI rem, MPI num, MPI den);
+int mpi_tdiv_qr(MPI quot, MPI rem, MPI num, MPI den);
+int mpi_tdiv_q_2exp(MPI w, MPI u, unsigned count);
+int mpi_divisible_ui(const MPI dividend, ulong divisor);
+
+/*-- mpi-gcd.c --*/
+int mpi_gcd(MPI g, const MPI a, const MPI b);
+
+/*-- mpi-pow.c --*/
+int mpi_pow(MPI w, MPI u, MPI v);
+int mpi_powm(MPI res, MPI base, MPI exp, MPI mod);
+
+/*-- mpi-mpow.c --*/
+int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI mod);
+
+/*-- mpi-cmp.c --*/
+int mpi_cmp_ui(MPI u, ulong v);
+int mpi_cmp(MPI u, MPI v);
+
+/*-- mpi-scan.c --*/
+int mpi_getbyte(MPI a, unsigned idx);
+void mpi_putbyte(MPI a, unsigned idx, int value);
+unsigned mpi_trailing_zeros(MPI a);
+
+/*-- mpi-bit.c --*/
+void mpi_normalize(MPI a);
+unsigned mpi_get_nbits(MPI a);
+int mpi_test_bit(MPI a, unsigned n);
+int mpi_set_bit(MPI a, unsigned n);
+int mpi_set_highbit(MPI a, unsigned n);
+void mpi_clear_highbit(MPI a, unsigned n);
+void mpi_clear_bit(MPI a, unsigned n);
+int mpi_rshift(MPI x, MPI a, unsigned n);
+
+/*-- mpi-inv.c --*/
+int mpi_invm(MPI x, MPI u, MPI v);
+
+#endif /*G10_MPI_H */
lib/mpi/longlong.h new file +1478 -0

1,478 lines not on this page · raw message

lib/mpi/mpi-inline.h new file +122 -0

122 lines not on this page · raw message

lib/mpi/mpi-internal.h new file +261 -0

261 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#8 lore raw

Re: [PATCH v2.2 2/7] crypto: GnuPG based MPI lib - header files (part 2)

Quoted 10 lines · Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

lib/mpi/longlong.h line 1435

Quoted 8 lines
lib/mpi/longlong.h new file +7 -0
 
+	/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
+#if !defined(udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#undef count_leading_zeros

Why is this #undef here? It's not present in mpi/longlong.h from Ubuntu's gnupg-1.4.10, and causing ...

Quoted 16 lines
lib/mpi/longlong.h new file +16 -0
+#if !defined(count_leading_zeros)
+	extern
+#ifdef __STDC__
+			const
+#endif
+			unsigned char __clz_tab[];
+#define count_leading_zeros(count, x) \
+do { \
+	UWtype __xr = (x); \
+	UWtype __a; \
+	\
+	if (W_TYPE_SIZE <= 32) { \
+		__a = __xr < ((UWtype) 1 << 2*__BITS4) \
+		? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
+		: (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4); \
+	} \

lib/mpi/longlong.h line 1461

Quoted 10 lines
lib/mpi/longlong.h new file +10 -0
+	else { \
+		for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+			if (((__xr >> __a) & 0xff) != 0) \
+				break; \
+	} \
+	\
+	(count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+} while (0)
+	/* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

lib/mpi/longlong.h:1483:1: warning: "COUNT_LEADING_ZEROS_0" redefined lib/mpi/longlong.h:610:1: warning: this is the location of the previous definition

on m68k/allmodconfig.

I'm also wondering why this warning is not seen on other arches, e.g. PPC #defines COUNT_LEADING_ZEROS_0 to 32, just like m68k.

Quoted 1 line

+#endif

I suppose the plan is to clean up this header file, as lots of its functionality is already present in the kernel sources in some other way (e.g. arch/m68k/lib/muldi3.c)?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#9 lore raw

Re: [PATCH v2.2 2/7] crypto: GnuPG based MPI lib - header files (part 2)

In reply to Dmitry Kasatkin
Quoted 10 lines · Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

lib/mpi/longlong.h line 1435

Quoted 8 lines
lib/mpi/longlong.h new file +7 -0
 
+	/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
+#if !defined(udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#undef count_leading_zeros

Why is this #undef here? It's not present in mpi/longlong.h from Ubuntu's gnupg-1.4.10, and causing ...

Quoted 16 lines
lib/mpi/longlong.h new file +16 -0
+#if !defined(count_leading_zeros)
+	extern
+#ifdef __STDC__
+			const
+#endif
+			unsigned char __clz_tab[];
+#define count_leading_zeros(count, x) \
+do { \
+	UWtype __xr = (x); \
+	UWtype __a; \
+	\
+	if (W_TYPE_SIZE <= 32) { \
+		__a = __xr < ((UWtype) 1 << 2*__BITS4) \
+		? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
+		: (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4); \
+	} \

lib/mpi/longlong.h line 1461

Quoted 10 lines
lib/mpi/longlong.h new file +10 -0
+	else { \
+		for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+			if (((__xr >> __a) & 0xff) != 0) \
+				break; \
+	} \
+	\
+	(count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+} while (0)
+	/* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

lib/mpi/longlong.h:1483:1: warning: "COUNT_LEADING_ZEROS_0" redefined lib/mpi/longlong.h:610:1: warning: this is the location of the previous definition

on m68k/allmodconfig.

I'm also wondering why this warning is not seen on other arches, e.g. PPC #defines COUNT_LEADING_ZEROS_0 to 32, just like m68k.

Quoted 1 line

+#endif

I suppose the plan is to clean up this header file, as lots of its functionality is already present in the kernel sources in some other way (e.g. arch/m68k/lib/muldi3.c)?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#10 lore raw

Re: [PATCH v2.2 2/7] crypto: GnuPG based MPI lib - header files (part 2)

Ping?

Quoted 55 lines · Geert Uytterhoeven
Quoted 10 lines · Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

lib/mpi/longlong.h line 1435

Quoted 8 lines
lib/mpi/longlong.h new file +7 -0
 
+     /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
+#if !defined(udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#undef count_leading_zeros

Why is this #undef here? It's not present in mpi/longlong.h from Ubuntu's gnupg-1.4.10, and causing ...

Quoted 16 lines
lib/mpi/longlong.h new file +16 -0
+#if !defined(count_leading_zeros)
+     extern
+#ifdef __STDC__
+                     const
+#endif
+                     unsigned char __clz_tab[];
+#define count_leading_zeros(count, x) \
+do { \
+     UWtype __xr = (x); \
+     UWtype __a; \
+     \
+     if (W_TYPE_SIZE <= 32) { \
+             __a = __xr < ((UWtype) 1 << 2*__BITS4) \
+             ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
+             : (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4); \
+     } \

lib/mpi/longlong.h line 1461

Quoted 10 lines
lib/mpi/longlong.h new file +10 -0
+     else { \
+             for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+                     if (((__xr >> __a) & 0xff) != 0) \
+                             break; \
+     } \
+     \
+     (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+} while (0)
+     /* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

lib/mpi/longlong.h:1483:1: warning: "COUNT_LEADING_ZEROS_0" redefined lib/mpi/longlong.h:610:1: warning: this is the location of the previous definition

on m68k/allmodconfig.

Quoted 8 lines

I'm also wondering why this warning is not seen on other arches, e.g. PPC #defines COUNT_LEADING_ZEROS_0 to 32, just like m68k.

Quoted 1 line

+#endif

I suppose the plan is to clean up this header file, as lots of its functionality is already present in the kernel sources in some other way (e.g. arch/m68k/lib/muldi3.c)?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#11 lore raw

Re: [PATCH v2.2 2/7] crypto: GnuPG based MPI lib - header files (part 2)

Quoted 74 lines · Geert Uytterhoeven

Ping?

Quoted 55 lines · Geert Uytterhoeven
Quoted 10 lines · Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

lib/mpi/longlong.h line 1435

Quoted 8 lines
lib/mpi/longlong.h new file +7 -0
 
+     /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
+#if !defined(udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#undef count_leading_zeros

Why is this #undef here? It's not present in mpi/longlong.h from Ubuntu's gnupg-1.4.10, and causing ...

Quoted 16 lines
lib/mpi/longlong.h new file +16 -0
+#if !defined(count_leading_zeros)
+     extern
+#ifdef __STDC__
+                     const
+#endif
+                     unsigned char __clz_tab[];
+#define count_leading_zeros(count, x) \
+do { \
+     UWtype __xr = (x); \
+     UWtype __a; \
+     \
+     if (W_TYPE_SIZE <= 32) { \
+             __a = __xr < ((UWtype) 1 << 2*__BITS4) \
+             ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
+             : (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4); \
+     } \

lib/mpi/longlong.h line 1461

Quoted 10 lines
lib/mpi/longlong.h new file +10 -0
+     else { \
+             for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+                     if (((__xr >> __a) & 0xff) != 0) \
+                             break; \
+     } \
+     \
+     (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+} while (0)
+     /* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

lib/mpi/longlong.h:1483:1: warning: "COUNT_LEADING_ZEROS_0" redefined lib/mpi/longlong.h:610:1: warning: this is the location of the previous definition

on m68k/allmodconfig.

Quoted 8 lines

I'm also wondering why this warning is not seen on other arches, e.g. PPC #defines COUNT_LEADING_ZEROS_0 to 32, just like m68k.

Quoted 1 line

+#endif

I suppose the plan is to clean up this header file, as lots of its functionality is already present in the kernel sources in some other way (e.g. arch/m68k/lib/muldi3.c)?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

Quoted 8 lines

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Hello,

There are things to cleanup...
It takes a bit of time.

- Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH v2.2 2/7] crypto: GnuPG based MPI lib - header files (part 2)

In reply to Geert Uytterhoeven
Quoted 74 lines · Geert Uytterhoeven

Ping?

Quoted 55 lines · Geert Uytterhoeven
Quoted 10 lines · Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

lib/mpi/longlong.h line 1435

Quoted 8 lines
lib/mpi/longlong.h new file +7 -0
 
+     /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
+#if !defined(udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#undef count_leading_zeros

Why is this #undef here? It's not present in mpi/longlong.h from Ubuntu's gnupg-1.4.10, and causing ...

Quoted 16 lines
lib/mpi/longlong.h new file +16 -0
+#if !defined(count_leading_zeros)
+     extern
+#ifdef __STDC__
+                     const
+#endif
+                     unsigned char __clz_tab[];
+#define count_leading_zeros(count, x) \
+do { \
+     UWtype __xr = (x); \
+     UWtype __a; \
+     \
+     if (W_TYPE_SIZE <= 32) { \
+             __a = __xr < ((UWtype) 1 << 2*__BITS4) \
+             ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
+             : (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4); \
+     } \

lib/mpi/longlong.h line 1461

Quoted 10 lines
lib/mpi/longlong.h new file +10 -0
+     else { \
+             for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+                     if (((__xr >> __a) & 0xff) != 0) \
+                             break; \
+     } \
+     \
+     (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+} while (0)
+     /* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

lib/mpi/longlong.h:1483:1: warning: "COUNT_LEADING_ZEROS_0" redefined lib/mpi/longlong.h:610:1: warning: this is the location of the previous definition

on m68k/allmodconfig.

Quoted 8 lines

I'm also wondering why this warning is not seen on other arches, e.g. PPC #defines COUNT_LEADING_ZEROS_0 to 32, just like m68k.

Quoted 1 line

+#endif

I suppose the plan is to clean up this header file, as lots of its functionality is already present in the kernel sources in some other way (e.g. arch/m68k/lib/muldi3.c)?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

Quoted 8 lines

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Hello,

There are things to cleanup...
It takes a bit of time.

- Dmitry

#13 lore raw

Re: [PATCH v2.2 2/7] crypto: GnuPG based MPI lib - header files (part 2)

In reply to Geert Uytterhoeven

Ping?

Quoted 55 lines · Geert Uytterhoeven
Quoted 10 lines · Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

lib/mpi/longlong.h line 1435

Quoted 8 lines
lib/mpi/longlong.h new file +7 -0
 
+     /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
+#if !defined(udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#undef count_leading_zeros

Why is this #undef here? It's not present in mpi/longlong.h from Ubuntu's gnupg-1.4.10, and causing ...

Quoted 16 lines
lib/mpi/longlong.h new file +16 -0
+#if !defined(count_leading_zeros)
+     extern
+#ifdef __STDC__
+                     const
+#endif
+                     unsigned char __clz_tab[];
+#define count_leading_zeros(count, x) \
+do { \
+     UWtype __xr = (x); \
+     UWtype __a; \
+     \
+     if (W_TYPE_SIZE <= 32) { \
+             __a = __xr < ((UWtype) 1 << 2*__BITS4) \
+             ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
+             : (__xr < ((UWtype) 1 << 3*__BITS4) ?  2*__BITS4 : 3*__BITS4); \
+     } \

lib/mpi/longlong.h line 1461

Quoted 10 lines
lib/mpi/longlong.h new file +10 -0
+     else { \
+             for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+                     if (((__xr >> __a) & 0xff) != 0) \
+                             break; \
+     } \
+     \
+     (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+} while (0)
+     /* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

lib/mpi/longlong.h:1483:1: warning: "COUNT_LEADING_ZEROS_0" redefined lib/mpi/longlong.h:610:1: warning: this is the location of the previous definition

on m68k/allmodconfig.

Quoted 8 lines

I'm also wondering why this warning is not seen on other arches, e.g. PPC #defines COUNT_LEADING_ZEROS_0 to 32, just like m68k.

Quoted 1 line

+#endif

I suppose the plan is to clean up this header file, as lots of its functionality is already present in the kernel sources in some other way (e.g. arch/m68k/lib/muldi3.c)?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#14 lore raw

PATCH 3/7 crypto: GnuPG based MPI lib - make files (part 3)

In reply to Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

Due to patch size limitation, the patch is divided into 4 parts.

---
 lib/Kconfig      |    7 +++++++
 lib/Makefile     |    2 ++
 lib/mpi/Makefile |   22 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 lib/mpi/Makefile
lib/Kconfig +7 -0
index 6c695ff..f69ce08 100644
@@ -279,4 +279,11 @@ config CORDIC
 config LLIST
 	bool
 
+config MPILIB
+	tristate "Multiprecision maths library"
+	help
+	  Multiprecision maths library from GnuPG.
+	  It is used to implement RSA digital signature verification,
+	  which is used by IMA/EVM digital signature extension.
+
 endmenu
lib/Makefile +2 -0
index d5d175c..97705ae 100644
@@ -117,6 +117,8 @@ obj-$(CONFIG_CORDIC) += cordic.o
 
 obj-$(CONFIG_LLIST) += llist.o
 
+obj-$(CONFIG_MPILIB) += mpi/
+
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
 
lib/mpi/Makefile new file +22 -0
new file mode 100644
index 0000000..0c1c6c3
@@ -0,0 +1,22 @@
+#
+# MPI multiprecision maths library (from gpg)
+#
+
+obj-$(CONFIG_MPILIB) = mpi.o
+
+mpi-y = \
+	generic_mpih-lshift.o		\
+	generic_mpih-mul1.o		\
+	generic_mpih-mul2.o		\
+	generic_mpih-mul3.o		\
+	generic_mpih-rshift.o		\
+	generic_mpih-sub1.o		\
+	generic_mpih-add1.o		\
+	mpicoder.o			\
+	mpi-bit.o			\
+	mpih-cmp.o			\
+	mpih-div.o			\
+	mpih-mul.o			\
+	mpi-pow.o			\
+	mpiutil.o
+
Signature · 1 line
1.7.4.1
#15 lore raw

PATCH 4/7 crypto: GnuPG based MPI lib - additional sources (part 4)

In reply to Dmitry Kasatkin

Adds the multi-precision-integer maths library which was originally taken from GnuPG and ported to the kernel by (among others) David Howells. This version is taken from Fedora kernel 2.6.32-71.14.1.el6.
The difference is that checkpatch reported errors and warnings have been fixed.

This library is used to implemenet RSA digital signature verification used in IMA/EVM integrity protection subsystem.

Due to patch size limitation, the patch is divided into 4 parts.

This code is unnecessary for RSA digital signature verification, but for completeness it is included here and can be compiled, if CONFIG_MPILIB_EXTRA is enabled.

---
 lib/Kconfig                    |   10 ++
 lib/mpi/Makefile               |   11 ++
 lib/mpi/generic_mpi-asm-defs.h |    4 +
 lib/mpi/mpi-add.c              |  234 ++++++++++++++++++++++++++++
 lib/mpi/mpi-cmp.c              |   68 ++++++++
 lib/mpi/mpi-div.c              |  333 ++++++++++++++++++++++++++++++++++++++++
 lib/mpi/mpi-gcd.c              |   59 +++++++
 lib/mpi/mpi-inline.c           |   31 ++++
 lib/mpi/mpi-inv.c              |  187 ++++++++++++++++++++++
 lib/mpi/mpi-mpow.c             |  133 ++++++++++++++++
 lib/mpi/mpi-mul.c              |  194 +++++++++++++++++++++++
 lib/mpi/mpi-scan.c             |  136 ++++++++++++++++
 12 files changed, 1400 insertions(+), 0 deletions(-)
 create mode 100644 lib/mpi/generic_mpi-asm-defs.h
 create mode 100644 lib/mpi/mpi-add.c
 create mode 100644 lib/mpi/mpi-cmp.c
 create mode 100644 lib/mpi/mpi-div.c
 create mode 100644 lib/mpi/mpi-gcd.c
 create mode 100644 lib/mpi/mpi-inline.c
 create mode 100644 lib/mpi/mpi-inv.c
 create mode 100644 lib/mpi/mpi-mpow.c
 create mode 100644 lib/mpi/mpi-mul.c
 create mode 100644 lib/mpi/mpi-scan.c
lib/Kconfig +10 -0
index f69ce08..b5dd7ef 100644
@@ -286,4 +286,14 @@ config MPILIB
 	  It is used to implement RSA digital signature verification,
 	  which is used by IMA/EVM digital signature extension.
 
+config MPILIB_EXTRA
+	bool "Multiprecision maths library - additional sources"
+	depends on MPILIB
+	help
+	  Multiprecision maths library from GnuPG.
+	  It is used to implement RSA digital signature verification,
+	  which is used by IMA/EVM digital signature extension.
+	  This code in unnecessary for RSA digital signature verification,
+	  and can be compiled if needed.	  
+
 endmenu
lib/mpi/Makefile +11 -0
index 0c1c6c3..5756716 100644
@@ -20,3 +20,14 @@ mpi-y = \
 	mpi-pow.o			\
 	mpiutil.o
 
+mpi-$(CONFIG_MPILIB_EXTRA) += \
+	mpi-add.o			\
+	mpi-div.o			\
+	mpi-cmp.o			\
+	mpi-gcd.o			\
+	mpi-inline.o			\
+	mpi-inv.o			\
+	mpi-mpow.o			\
+	mpi-mul.o			\
+	mpi-scan.o			\
+
lib/mpi/generic_mpi-asm-defs.h new file +4 -0
new file mode 100644
index 0000000..047d1f5
@@ -0,0 +1,4 @@
+/* This file defines some basic constants for the MPI machinery.  We
+ * need to define the types on a per-CPU basis, so it is done with
+ * this file here.  */
+#define BYTES_PER_MPI_LIMB  (SIZEOF_UNSIGNED_LONG)
lib/mpi/mpi-add.c new file +234 -0

234 lines not on this page · raw message

lib/mpi/mpi-cmp.c new file +68 -0

68 lines not on this page · raw message

lib/mpi/mpi-div.c new file +333 -0

333 lines not on this page · raw message

lib/mpi/mpi-gcd.c new file +59 -0

59 lines not on this page · raw message

lib/mpi/mpi-inline.c new file +31 -0
new file mode 100644
index 0000000..654f68a
@@ -0,0 +1,31 @@
+/* mpi-inline.c
+ * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* put the inline functions as real functions into the lib */
+#define G10_MPI_INLINE_DECL
+
+#include "mpi-internal.h"
+
+/* always include the header becuase it is only
+ * included by mpi-internal if __GCC__ is defined but we
+ * need it here in all cases and the above definition of
+ * of the macro allows us to do so
+ */
+#include "mpi-inline.h"
lib/mpi/mpi-inv.c new file +187 -0

187 lines not on this page · raw message

lib/mpi/mpi-mpow.c new file +133 -0

133 lines not on this page · raw message

lib/mpi/mpi-mul.c new file +194 -0

194 lines not on this page · raw message

lib/mpi/mpi-scan.c new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#16 lore raw

PATCH 5/7 crypto: digital signature verification support

In reply to Dmitry Kasatkin

This patch implements RSA digital signature verification using GnuPG library.

The format of the signature and the public key is defined by their respective headers. The signature header contains version information, algorithm, and keyid, which was used to generate the signature.
The key header contains version and algorythim type.
The payload of the signature and the key are multi-precision integers.

The signing and key management utilities evm-utils provide functionality to generate signatures and load keys into the kernel keyring. When the key is added to the kernel keyring, the keyid defines the name of the key.

---
 Documentation/digsig.txt |   97 ++++++++++++++++
 include/linux/digsig.h   |   64 +++++++++++
 lib/Kconfig              |    8 ++
 lib/Makefile             |    1 +
 lib/digsig.c             |  283 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 453 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/digsig.txt
 create mode 100644 include/linux/digsig.h
 create mode 100644 lib/digsig.c
Documentation/digsig.txt new file +97 -0
new file mode 100644
index 0000000..17dd866
@@ -0,0 +1,97 @@
+Digital Signature Verification API
+
+CONTENTS
+
+1. Introduction
+2. API
+3. User-space utilities
+
+
+1. Introduction
+
+Digital signature verification API provides a method to verify digital signature.
+Currently digital signatures are used by the IMA/EVM integrity protection subsystem.
+
+Digital signature verification is implemented using cut-down kernel port of
+GnuPG multi-precision integers (MPI) library. The kernel port provides
+memory allocation errors handling, has been refactored according to kernel
+coding style, and checkpatch.pl reported errors and warnings have been fixed.
+
+Public key and signature consist of header and MPIs.
+
+struct pubkey_hdr {
+	uint8_t		version;	/* key format version */
+	time_t		timestamp;	/* key made, always 0 for now */
+	uint8_t		algo;
+	uint8_t		nmpi;
+	char		mpi[0];
+} __packed;
+
+struct signature_hdr {
+	uint8_t		version;	/* signature format version */
+	time_t		timestamp;	/* signature made */
+	uint8_t		algo;
+	uint8_t		hash;
+	uint8_t		keyid[8];
+	uint8_t		nmpi;
+	char		mpi[0];
+} __packed;
+
+keyid equals to SHA1[12-19] over the total key content.
+Signature header is used as an input to generate a signature.
+Such approach insures that key or signature header could not be changed.
+It protects timestamp from been changed and can be used for rollback
+protection.
+
+2. API
+
+API currently includes only 1 function:
+
+	digsig_verify() - digital signature verification with public key
+	
+
+/**
+ * digsig_verify() - digital signature verification with public key
+ * @keyring:	keyring to search key in
+ * @sig:	digital signature
+ * @sigen:	length of the signature
+ * @data:	data
+ * @datalen:	length of the data
+ * @return:	0 on success, -EINVAL otherwise
+ *
+ * Verifies data integrity against digital signature.
+ * Currently only RSA is supported.
+ * Normally hash of the content is used as a data for this function.
+ *
+ */
+int digsig_verify(struct key *keyring, const char *sig, int siglen,
+						const char *data, int datalen);
+
+3. User-space utilities
+
+The signing and key management utilities evm-utils provide functionality
+to generate signatures, to load keys into the kernel keyring.
+Keys can be in PEM or converted to the kernel format.
+When the key is added to the kernel keyring, the keyid defines the name
+of the key: 5D2B05FC633EE3E8 in the example bellow.
+
+Here is example output of the keyctl utility.
+
+$ keyctl show
+Session Keyring
+       -3 --alswrv      0     0  keyring: _ses
+603976250 --alswrv      0    -1   \_ keyring: _uid.0
+817777377 --alswrv      0     0       \_ user: kmk
+891974900 --alswrv      0     0       \_ encrypted: evm-key
+170323636 --alswrv      0     0       \_ keyring: _module
+548221616 --alswrv      0     0       \_ keyring: _ima
+128198054 --alswrv      0     0       \_ keyring: _evm
+
+$ keyctl list 128198054
+1 key in keyring:
+620789745: --alswrv     0     0 user: 5D2B05FC633EE3E8
+
+
+Dmitry Kasatkin
+06.10.2011
+
include/linux/digsig.h new file +64 -0

64 lines not on this page · raw message

lib/Kconfig +8 -0
index b5dd7ef..3ff216c 100644
@@ -296,4 +296,12 @@ config MPILIB_EXTRA
 	  This code in unnecessary for RSA digital signature verification,
 	  and can be compiled if needed.	  
 
+config DIGSIG
+	tristate "In-kernel signature checker"
+	depends on CRYPTO
+	select MPILIB
+	help
+	  Digital signature verification. Currently only RSA is supported.
+	  Implementation is done using GnuPG MPI library
+
 endmenu
lib/Makefile +1 -0
index 97705ae..52a6b28 100644
@@ -118,6 +118,7 @@ obj-$(CONFIG_CORDIC) += cordic.o
 obj-$(CONFIG_LLIST) += llist.o
 
 obj-$(CONFIG_MPILIB) += mpi/
+obj-$(CONFIG_DIGSIG) += digsig.o
 
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
lib/digsig.c new file +283 -0

283 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#17 lore raw

PATCH 6/7 integrity: digital signature verification using multiple keyrings

In reply to Dmitry Kasatkin

Define separate keyrings for each of the different use cases - evm, ima, and modules. Using different keyrings improves search performance, and also allows "locking" specific keyring to prevent adding new keys. This is useful for evm and module keyrings, when keys are usually only added from initramfs.

---
 security/integrity/Kconfig     |   14 +++++++++++
 security/integrity/Makefile    |    1 +
 security/integrity/digsig.c    |   48 ++++++++++++++++++++++++++++++++++++++++
 security/integrity/integrity.h |   20 ++++++++++++++++
 4 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 security/integrity/digsig.c
security/integrity/Kconfig +14 -0
index 4bf00ac..d87fa2a 100644
@@ -3,5 +3,19 @@ config INTEGRITY
 	def_bool y
 	depends on IMA || EVM
 
+config INTEGRITY_DIGSIG
+	boolean "Digital signature verification using multiple keyrings"
+	depends on INTEGRITY
+	default n
+	select DIGSIG
+	help
+	  This option enables digital signature verification support
+	  using multiple keyrings. It defines separate keyrings for each
+	  of the different use cases - evm, ima, and modules.
+	  Different keyrings improves search performance, but also allow
+	  to "lock" certain keyring to prevent adding new keys.
+	  This is useful for evm and module keyrings, when keys are
+	  usually only added from initramfs.
+
 source security/integrity/ima/Kconfig
 source security/integrity/evm/Kconfig
security/integrity/Makefile +1 -0
index 0ae44ae..bece056 100644
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_INTEGRITY) += integrity.o
+obj-$(CONFIG_INTEGRITY_DIGSIG) += digsig.o
 
 integrity-y := iint.o
 
security/integrity/digsig.c new file +48 -0

48 lines not on this page · raw message

security/integrity/integrity.h +20 -0
index e898094..9fc723b 100644
@@ -51,5 +51,25 @@ struct integrity_iint_cache {
 struct integrity_iint_cache *integrity_iint_insert(struct inode *inode);
 struct integrity_iint_cache *integrity_iint_find(struct inode *inode);
 
+#define INTEGRITY_KEYRING_EVM		0
+#define INTEGRITY_KEYRING_MODULE	1
+#define INTEGRITY_KEYRING_IMA		2
+#define INTEGRITY_KEYRING_MAX		3
+
+#ifdef CONFIG_INTEGRITY_DIGSIG
+
+int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
+					const char *digest, int digestlen);
+
+#else
+
+static inline int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
+					const char *digest, int digestlen)
+{
+	return -EOPNOTSUPP;
+}
+
+#endif /* CONFIG_INTEGRITY_DIGSIG */
+
 /* set during initialization */
 extern int iint_initialized;
Signature · 1 line
1.7.4.1
Acked-by on v1 6/7
#18 lore raw

Re: [PATCH v2.2 6/7] integrity: digital signature verification using multiple keyrings

Quoted 7 lines · Dmitry Kasatkin

Define separate keyrings for each of the different use cases - evm, ima, and modules. Using different keyrings improves search performance, and also allows "locking" specific keyring to prevent adding new keys. This is useful for evm and module keyrings, when keys are usually only added from initramfs.

Thanks Dmitry! Other than the couple of trailing whitespaces, the patches look good. I think adding the word 'public', above, to 'adding new keys' clarifies that the keyrings are only used for the digital signatures.

Quoted 128 lines
---
 security/integrity/Kconfig     |   14 +++++++++++
 security/integrity/Makefile    |    1 +
 security/integrity/digsig.c    |   48 ++++++++++++++++++++++++++++++++++++++++
 security/integrity/integrity.h |   20 ++++++++++++++++
 4 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 security/integrity/digsig.c
security/integrity/Kconfig +14 -0
index 4bf00ac..d87fa2a 100644
@@ -3,5 +3,19 @@ config INTEGRITY
 	def_bool y
 	depends on IMA || EVM
 
+config INTEGRITY_DIGSIG
+	boolean "Digital signature verification using multiple keyrings"
+	depends on INTEGRITY
+	default n
+	select DIGSIG
+	help
+	  This option enables digital signature verification support
+	  using multiple keyrings. It defines separate keyrings for each
+	  of the different use cases - evm, ima, and modules.
+	  Different keyrings improves search performance, but also allow
+	  to "lock" certain keyring to prevent adding new keys.
+	  This is useful for evm and module keyrings, when keys are
+	  usually only added from initramfs.
+
 source security/integrity/ima/Kconfig
 source security/integrity/evm/Kconfig
security/integrity/Makefile +1 -0
index 0ae44ae..bece056 100644
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_INTEGRITY) += integrity.o
+obj-$(CONFIG_INTEGRITY_DIGSIG) += digsig.o
 
 integrity-y := iint.o
 
security/integrity/digsig.c new file +48 -0
new file mode 100644
index 0000000..b5d1e01
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * Author:
+ * Dmitry Kasatkin <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 of the License.
+ *
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/err.h>
+#include <linux/rbtree.h>
+#include <linux/key-type.h>
+#include <linux/digsig.h>
+
+#include "integrity.h"
+
+static struct key *keyring[INTEGRITY_KEYRING_MAX];
+
+static const char *keyring_name[INTEGRITY_KEYRING_MAX] = {
+	"_evm",
+	"_module",
+	"_ima",
+};
+
+int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
+					const char *digest, int digestlen)
+{
+	if (id >= INTEGRITY_KEYRING_MAX)
+		return -EINVAL;
+
+	if (!keyring[id]) {
+		keyring[id] =
+			request_key(&key_type_keyring, keyring_name[id], NULL);
+		if (IS_ERR(keyring[id])) {
+			pr_err("no %s keyring: %ld\n", keyring_name[id],
+							PTR_ERR(keyring[id]));
+			keyring[id] = NULL;
+			return PTR_ERR(keyring[id]);
+		}
+	}
+
+	return digsig_verify(keyring[id], sig, siglen, digest, digestlen);
+}
security/integrity/integrity.h +20 -0
index e898094..9fc723b 100644
@@ -51,5 +51,25 @@ struct integrity_iint_cache {
 struct integrity_iint_cache *integrity_iint_insert(struct inode *inode);
 struct integrity_iint_cache *integrity_iint_find(struct inode *inode);
 
+#define INTEGRITY_KEYRING_EVM		0
+#define INTEGRITY_KEYRING_MODULE	1
+#define INTEGRITY_KEYRING_IMA		2
+#define INTEGRITY_KEYRING_MAX		3
+
+#ifdef CONFIG_INTEGRITY_DIGSIG
+
+int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
+					const char *digest, int digestlen);
+
+#else
+
+static inline int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
+					const char *digest, int digestlen)
+{
+	return -EOPNOTSUPP;
+}
+
+#endif /* CONFIG_INTEGRITY_DIGSIG */
+
 /* set during initialization */
 extern int iint_initialized;
#19 lore raw

PATCH 7/7 evm: digital signature verification support

In reply to Dmitry Kasatkin

This patch adds support for digital signature verification to EVM. With this feature file metadata can be protected using digital signature instead of an HMAC. When building an image, which has to be flashed to different devices, an HMAC cannot be used to sign file metadata, because the HMAC key should be different on every device.

---
 security/integrity/evm/evm.h        |   12 +++++
 security/integrity/evm/evm_crypto.c |   66 ++++++++++++++++++------
 security/integrity/evm/evm_main.c   |   94 ++++++++++++++++++++++++++++++-----
 3 files changed, 142 insertions(+), 30 deletions(-)
security/integrity/evm/evm.h +12 -0
index d320f51..c885247 100644
@@ -12,14 +12,21 @@
  * File: evm.h
  *
  */
+
+#ifndef __INTEGRITY_EVM_H
+#define __INTEGRITY_EVM_H
+
 #include <linux/xattr.h>
 #include <linux/security.h>
+
 #include "../integrity.h"
 
 extern int evm_initialized;
 extern char *evm_hmac;
+extern char *evm_hash;
 
 extern struct crypto_shash *hmac_tfm;
+extern struct crypto_shash *hash_tfm;
 
 /* List of EVM protected security xattrs */
 extern char *evm_config_xattrnames[];
@@ -32,7 +39,12 @@ extern int evm_update_evmxattr(struct dentry *dentry,
 extern int evm_calc_hmac(struct dentry *dentry, const char *req_xattr_name,
 			 const char *req_xattr_value,
 			 size_t req_xattr_value_len, char *digest);
+extern int evm_calc_hash(struct dentry *dentry, const char *req_xattr_name,
+			 const char *req_xattr_value,
+			 size_t req_xattr_value_len, char *digest);
 extern int evm_init_hmac(struct inode *inode, const struct xattr *xattr,
 			 char *hmac_val);
 extern int evm_init_secfs(void);
 extern void evm_cleanup_secfs(void);
+
+#endif
security/integrity/evm/evm_crypto.c +49 -17

112 lines not on this page · raw message

security/integrity/evm/evm_main.c +81 -13

137 lines not on this page · raw message

Signature · 1 line
1.7.4.1