evm: digital signature verification extension
Subsystems (6)
cover evm: digital signature verification extension
Hello,
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 | 34 + 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/generic_udiv-w-sdiv.c | 106 +++ 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 + 42 files changed, 6904 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/generic_udiv-w-sdiv.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
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
@@ -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
James Morris
maintainerRe: [PATCH v2.1 1/7] crypto: GnuPG based MPI lib - source files (part 1)
lib/mpi/mpiutil.c line 34
Quoted 5 lines · Dmitry Kasatkin
lib/mpi/mpiutil.c new file +5
-0+MPI mpi_alloc (unsigned nlimbs) +{ +MPI a; + + a = (MPI )kmalloc (sizeof *a,GFP_KERNEL );
Generally, typedef structs are frowned upon in the kernel. I'd prefer to see this (and any others) changed to a normal type.
Also, kmalloc return values do not need to be cast, they're void *.
Quoted 1 line
+EXPORT_SYMBOL(mpi_alloc);
New interfaces should be EXPORT_SYMBOL_GPL.
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH v2.1 1/7] crypto: GnuPG based MPI lib - source files (part 1)
From Kernel Docbook
Similar to <function>EXPORT_SYMBOL()</function> except that the symbols exported by <function>EXPORT_SYMBOL_GPL()</function> can only be seen by modules with a <function>MODULE_LICENSE()</function> that specifies a GPL compatible license. It implies that the function is considered an internal implementation issue, and not really an interface.
"not really an interface"....
Should it really be EXPORT_SYMBOL_GPL?
- Dmitry
Quoted 13 lines · James Morris
lib/mpi/mpiutil.c line 34
Quoted 5 lines · Dmitry Kasatkin
lib/mpi/mpiutil.c new file +5
-0+MPI mpi_alloc (unsigned nlimbs) +{ + MPI a; + + a = (MPI) kmalloc(sizeof *a, GFP_KERNEL);Generally, typedef structs are frowned upon in the kernel. I'd prefer to see this (and any others) changed to a normal type.
Also, kmalloc return values do not need to be cast, they're void *.
Quoted 9 lines
Quoted 1 line
+EXPORT_SYMBOL(mpi_alloc);
New interfaces should be
EXPORT_SYMBOL_GPL.--
James Morris
<[email protected]>
--
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
Re: [PATCH v2.1 1/7] crypto: GnuPG based MPI lib - source files (part 1)
Quoted 9 lines · Dmitry
From Kernel Docbook
Similar to <function>EXPORT_SYMBOL()</function> except that the symbols exported by <function>EXPORT_SYMBOL_GPL()</function> can only be seen by modules with a <function>MODULE_LICENSE()</function> that specifies a GPL compatible license. It implies that the function is considered an internal implementation issue, and not really an interface.
Quoted 30 lines
"not really an interface"....
Should it really be
EXPORT_SYMBOL_GPL?- Dmitry
Quoted 22 lines · James Morris
lib/mpi/mpiutil.c line 34
Quoted 5 lines · Dmitry Kasatkin
lib/mpi/mpiutil.c new file +5
-0+MPI mpi_alloc (unsigned nlimbs) +{ + MPI a; + + a = (MPI) kmalloc(sizeof *a, GFP_KERNEL);Generally, typedef structs are frowned upon in the kernel. I'd prefer to see this (and any others) changed to a normal type.
Also, kmalloc return values do not need to be cast, they're void *.
Quoted 1 line
+EXPORT_SYMBOL(mpi_alloc);
New interfaces should be
EXPORT_SYMBOL_GPL.--
James Morris
<[email protected]>
Hello James,
Also please let me know about other things so that I could fix them as well...
Thanks!
- 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
Re: [PATCH v2.1 1/7] crypto: GnuPG based MPI lib - source files (part 1)
In reply to Kasatkin, DmitryQuoted 9 lines · Dmitry
Quoted 1 line
From Kernel Docbook
Similar to <function>EXPORT_SYMBOL()</function> except that the symbols exported by <function>EXPORT_SYMBOL_GPL()</function> can only be seen by modules with a <function>MODULE_LICENSE()</function> that specifies a GPL compatible license. It implies that the function is considered an internal implementation issue, and not really an interface.
Quoted 3 lines
"not really an interface"....
Should it really be
EXPORT_SYMBOL_GPL?
Yes.
Re: [PATCH v2.1 1/7] crypto: GnuPG based MPI lib - source files (part 1)
In reply to James MorrisQuoted 8 lines · James Morris
lib/mpi/mpiutil.c line 34
Quoted 5 lines
lib/mpi/mpiutil.c new file +5
-0+MPI mpi_alloc (unsigned nlimbs) +{ +MPI a; + + a = (MPI )kmalloc (sizeof *a,GFP_KERNEL );Generally, typedef structs are frowned upon in the kernel. I'd prefer to see this (and any others) changed to a normal type.
In this case, however, it makes it easier to compare back to the original code.
David
PATCH 2/7 crypto: GnuPG based MPI lib - header files (part 2)
In reply to Dmitry KasatkinAdds 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
@@ -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
PATCH 3/7 crypto: GnuPG based MPI lib - make files (part 3)
In reply to Dmitry KasatkinAdds 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
@@ -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
@@ -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
@@ -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
PATCH 4/7 crypto: GnuPG based MPI lib - additional sources (part 4)
In reply to Dmitry KasatkinAdds 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 | 12 ++ lib/mpi/generic_mpi-asm-defs.h | 4 + lib/mpi/generic_udiv-w-sdiv.c | 106 +++++++++++++ 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 ++++++++++++++++ 13 files changed, 1507 insertions(+), 0 deletions(-) create mode 100644 lib/mpi/generic_mpi-asm-defs.h create mode 100644 lib/mpi/generic_udiv-w-sdiv.c 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
@@ -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 +12 -0
@@ -20,3 +20,15 @@ mpi-y = \ mpi-pow.o \ mpiutil.o +mpi-$(CONFIG_MPILIB_EXTRA) += \ + generic_udiv-w-sdiv.o \ + 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
@@ -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/generic_udiv-w-sdiv.c new file +106 -0
106 lines not on this page · raw message
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
@@ -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
James Morris
maintainerRe: [PATCH v2.1 4/7] crypto: GnuPG based MPI lib - additional sources (part 4)
lib/mpi/generic_udiv-w-sdiv.c line 30
Quoted 5 lines · Dmitry Kasatkin
lib/mpi/generic_udiv-w-sdiv.c new file +5
-0+#if 0 /* not yet ported to MPI */ + +mpi_limb_t +mpihelp_udiv_w_sdiv (mpi_limp_t *rp, +mpi_limp_t *a1,mpi_limp_t *a0,mpi_limp_t *d)
Drop this if it's not working.
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH v2.1 4/7] crypto: GnuPG based MPI lib - additional sources (part 4)
Quoted 11 lines · James Morris
lib/mpi/generic_udiv-w-sdiv.c line 30
Quoted 5 lines · Dmitry Kasatkin
lib/mpi/generic_udiv-w-sdiv.c new file +5
-0+#if 0 /* not yet ported to MPI */ + +mpi_limb_t +mpihelp_udiv_w_sdiv (mpi_limp_t *rp, + mpi_limp_t *a1, mpi_limp_t *a0, mpi_limp_t *d)Drop this if it's not working.
Quoted 8 lines
--
James Morris
<[email protected]>
--
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
It is there for completeness and it will not be even compiled at all without CONFIG_MPILIB_EXTRA
Still remove?
- Dmitry
James Morris
maintainerRe: [PATCH v2.1 4/7] crypto: GnuPG based MPI lib - additional sources (part 4)
Quoted 4 lines · Dmitry
It is there for completeness and it will not be even compiled at all without
CONFIG_MPILIB_EXTRAStill remove?
Yes, please.
Signature · 2 lines
James Morris <[email protected]>
PATCH 5/7 crypto: digital signature verification support
In reply to Dmitry KasatkinThis 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
@@ -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
@@ -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
@@ -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
PATCH 6/7 integrity: digital signature verification using multiple keyrings
In reply to Dmitry KasatkinDefine 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
@@ -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
@@ -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
@@ -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
PATCH 7/7 evm: digital signature verification support
In reply to Dmitry KasatkinThis 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
@@ -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