aboutsummaryrefslogtreecommitdiff
path: root/openssl/trunk/doc/crypto/sha.pod
blob: 0ba315d6d7a336e0b54890dfcdff08b3818aab28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
=pod

=head1 NAME

SHA1, SHA1_Init, SHA1_Update, SHA1_Final - Secure Hash Algorithm

=head1 SYNOPSIS

 #include <openssl/sha.h>

 unsigned char *SHA1(const unsigned char *d, unsigned long n,
                  unsigned char *md);

 void SHA1_Init(SHA_CTX *c);
 void SHA1_Update(SHA_CTX *c, const void *data,
                  unsigned long len);
 void SHA1_Final(unsigned char *md, SHA_CTX *c);

=head1 DESCRIPTION

SHA-1 (Secure Hash Algorithm) is a cryptographic hash function with a
160 bit output.

SHA1() computes the SHA-1 message digest of the B<n>
bytes at B<d> and places it in B<md> (which must have space for
SHA_DIGEST_LENGTH == 20 bytes of output). If B<md> is NULL, the digest
is placed in a static array.

The following functions may be used if the message is not completely
stored in memory:

SHA1_Init() initializes a B<SHA_CTX> structure.

SHA1_Update() can be called repeatedly with chunks of the message to
be hashed (B<len> bytes at B<data>).

SHA1_Final() places the message digest in B<md>, which must have space
for SHA_DIGEST_LENGTH == 20 bytes of output, and erases the B<SHA_CTX>.

Applications should use the higher level functions
L<EVP_DigestInit(3)|EVP_DigestInit(3)>
etc. instead of calling the hash functions directly.

The predecessor of SHA-1, SHA, is also implemented, but it should be
used only when backward compatibility is required.

=head1 RETURN VALUES

SHA1() returns a pointer to the hash value. 

SHA1_Init(), SHA1_Update() and SHA1_Final() do not return values.

=head1 CONFORMING TO

SHA: US Federal Information Processing Standard FIPS PUB 180 (Secure Hash
Standard),
SHA-1: US Federal Information Processing Standard FIPS PUB 180-1 (Secure Hash
Standard),
ANSI X9.30

=head1 SEE ALSO

L<ripemd(3)|ripemd(3)>, L<hmac(3)|hmac(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>

=head1 HISTORY

SHA1(), SHA1_Init(), SHA1_Update() and SHA1_Final() are available in all
versions of SSLeay and OpenSSL.

=cut
h=zone-cleanup&id=7b53193bf93d5da765d45e2a703426c8f3b95c3c'>7b53193b
9376f9af
7b53193b


e3a139bc
bfdc3d37








07d3bed9
bfdc3d37
07d3bed9
bfdc3d37
a7cad7f4
07d3bed9

bfdc3d37
e3a139bc
bfdc3d37
















7b53193b
bfdc3d37
7b53193b
bfdc3d37
e3a139bc
bfdc3d37
7b53193b

f4e529b2

7b53193b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

                     
                                                          











                                                                             
 




                                                              
                    
 
               
              

             
             
            



             
 

                  



                                      
                                                          
 
                                                                                              
 
                             

        
 
                        
                              


               
                          








                                                              
            
                                                            
                                   
                                             
                                                                             

                         
                                                                                             
        
















                                                                                    
                                                    
                                                         
 
                                                                                               
 
                       

                                                   

                            
                   
#!/usr/bin/env python

# Copyright (C) 2012, 2013  SPARTA, Inc. a Parsons Company
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

"""This tool is used to import the IPv4/6 BGP table dumps
from routeviews.org into the RPKI Web Portal database.  If the
input file is a bzip2 compressed file, it will be decompressed
automatically."""

__version__ = '$Id$'

import optparse
import logging
import time
import random
import signal
import errno
import atexit
import fcntl
import sys
import os

import rpki.config

# configure django ORM
from rpki.gui.script_util import setup
setup()

from rpki.gui.routeview.util import import_routeviews_dump

default_url = 'http://archive.routeviews.org/oix-route-views/oix-full-snapshot-latest.dat.bz2'

class BadArgument(Exception):
    pass


def timed_out(*ignored):
    logging.error('timed out')
    sys.exit(1)


if __name__ == '__main__':
    myname = 'rpkigui-import-routes'

    cfg = rpki.config.argparser(section=myname, doc=__doc__)
    cfg.add_logging_arguments()
    args = cfg.argparser.parse_args()
    cfg.configure_logging(ident=myname, args=args)

    jitter = cfg.getint('jitter', section=myname, default=600)
    if jitter > 0:
        try:
            delay = random.SystemRandom().randint(0, jitter)
        except NotImplementedError:
            delay = random.randint(0, jitter)
        logging.info('jitter active, delaying startup for %d seconds', delay)
        time.sleep(delay)

    lockfile = cfg.get('lockfile', section=myname, default='/tmp/rpkigui-import-routes.lock')
    try:
        lock = os.open(lockfile, os.O_RDONLY | os.O_CREAT | os.O_NONBLOCK, 0666)
        fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
    except (IOError, OSError), e:
        if e.errno == errno.EAGAIN:
            logging.info('lock held by another process')
            sys.exit(0)
        else:
            logging.exception(e)
            sys.exit(1)

    filename = cfg.get('filename', section=myname, default=default_url)
    filetype = cfg.get('filetype', section=myname, default='text')
    download_dir = cfg.get('download-directory', section=myname, default='/var/tmp')

    timeout = cfg.getint('timeout', section=myname, default=5400)
    try:
        if timeout > 0:
            signal.signal(signal.SIGALRM, timed_out)
            signal.setitimer(signal.ITIMER_REAL, timeout)

        import_routeviews_dump(filename=filename, filetype=filetype, download_dir=download_dir)

        if timeout > 0:
            signal.setitimer(signal.ITIMER_REAL, 0)

    except Exception as e:
        logging.exception(e)
        sys.exit(1)