Viewing File: /usr/lib64/python2.7/site-packages/Crypto/Signature/PKCS1_PSS.pyo
ó
Bd\Rc @ sÞ d Z d d l m Z d Z d d g Z d d l Te j d d k re e j d d k re d d l Tn d d
l Z
d d l m Z m Z m
Z
d d l m Z d d d
„ ƒ YZ d „ Z d „ Z d „ Z d
d
d „ Z d
S( s‘ RSA digital signature protocol with appendix according to PKCS#1 PSS.
See RFC3447__ or the `original RSA Labs specification`__.
This scheme is more properly called ``RSASSA-PSS``.
For example, a sender may authenticate a message using SHA-1 and PSS like
this:
>>> from Crypto.Signature import PKCS1_PSS
>>> from Crypto.Hash import SHA
>>> from Crypto.PublicKey import RSA
>>> from Crypto import Random
>>>
>>> message = 'To be signed'
>>> key = RSA.importKey(open('privkey.der').read())
>>> h = SHA.new()
>>> h.update(message)
>>> signer = PKCS1_PSS.new(key)
>>> signature = PKCS1_PSS.sign(key)
At the receiver side, verification can be done like using the public part of
the RSA key:
>>> key = RSA.importKey(open('pubkey.der').read())
>>> h = SHA.new()
>>> h.update(message)
>>> verifier = PKCS1_PSS.new(key)
>>> if verifier.verify(h, signature):
>>> print "The signature is authentic."
>>> else:
>>> print "The signature is not authentic."
:undocumented: __revision__, __package__
.. __: http://www.ietf.org/rfc/rfc3447.txt
.. __: http://www.rsa.com/rsalabs/node.asp?id=2125
iÿÿÿÿ( t
nested_scopess $Id$t newt
PSS_SigScheme( t *i i i N( t
ceil_shiftt ceil_divt
long_to_bytes( t strxorc B s2 e Z d Z d „ Z d „ Z d „ Z d „ Z RS( sK This signature scheme can perform PKCS#1 PSS RSA signature or verification.c C s | | _ | | _ | | _ d S( s! Initialize this PKCS#1 PSS signature scheme object.
:Parameters:
key : an RSA key object
If a private half is given, both signature and verification are possible.
If a public half is given, only verification is possible.
mgfunc : callable
A mask generation function that accepts two parameters: a string to
use as seed, and the lenth of the mask to generate, in bytes.
saltLen : int
Length of the salt, in bytes.
N( t _keyt _saltLent _mgfunc( t selft keyt mgfunct saltLen( ( s@ /usr/lib64/python2.7/site-packages/Crypto/Signature/PKCS1_PSS.pyt __init__O s
c C s
| j j ƒ S( sC Return True if this cipher object can be used for signing messages.( R t has_private( R ( ( s@ /usr/lib64/python2.7/site-packages/Crypto/Signature/PKCS1_PSS.pyt can_sign` s c
sÎ | j j } | j d k r' ˆ j } n | j } | j rE | j } n ‡ f d † } t j j j | j j
ƒ } t | d ƒ } t ˆ | d | | | ƒ } | j j
| ƒ } t d ƒ | t | ƒ | } | S( sB Produce the PKCS#1 PSS signature of a message.
This function is named ``RSASSA-PSS-SIGN``, and is specified in
section 8.1.1 of RFC3447.
:Parameters:
mhash : hash object
The hash that was carried out over the message. This is an object
belonging to the `Crypto.Hash` module.
:Return: The PSS signature encoded as a string.
:Raise ValueError:
If the RSA key length is not sufficiently long to deal with the given
hash algorithm.
:Raise TypeError:
If the RSA key has no private half.
:attention: Modify the salt length and the mask generation function only
if you know what you are doing.
The receiver must use the same parameters too.
c s t | | ˆ ƒ S( N( t MGF1( t xt y( t mhash( s@ /usr/lib64/python2.7/site-packages/Crypto/Signature/PKCS1_PSS.pyt <lambda>† s i i i N( R t _randfuncR t Nonet digest_sizeR
t Cryptot Utilt numbert sizet nR t EMSA_PSS_ENCODEt decryptt bchrt len(
R R t randfunct sLent mgft modBitst kt emt mt S( ( R s@ /usr/lib64/python2.7/site-packages/Crypto/Signature/PKCS1_PSS.pyt signd s c
s | j d k r ˆ j } n | j } | j r9 | j } n ‡ f d † } t j j j | j j ƒ } t
| d ƒ } t | ƒ | k rˆ t S| j j
| d ƒ d } t
| d d ƒ } t d ƒ | t | ƒ | } y t ˆ | | d | | ƒ } Wn t k
rt SX| S( s Verify that a certain PKCS#1 PSS signature is authentic.
This function checks if the party holding the private half of the given
RSA key has really signed the message.
This function is called ``RSASSA-PSS-VERIFY``, and is specified in section
8.1.2 of RFC3447.
:Parameters:
mhash : hash object
The hash that was carried out over the message. This is an object
belonging to the `Crypto.Hash` module.
S : string
The signature that needs to be validated.
:Return: True if verification is correct. False otherwise.
c s t | | ˆ ƒ S( N( R ( R R ( R ( s@ /usr/lib64/python2.7/site-packages/Crypto/Signature/PKCS1_PSS.pyR ° s i i i N( R R R R
R R R R R R R R"