aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
Commit message (Expand)AuthorAgeFilesLines
* add encode_rfc6979_signature and refactor tests to use itPaul Kehrer2014-11-271-21/+1
* Update the license header for every source file, as well as the documentation.Alex Gaynor2014-11-161-12/+3
* move skip_if_empty to separate function for test coveragePaul Kehrer2014-10-251-1/+8
* Change how we represented that a test requires a backend.Alex Gaynor2014-10-231-19/+6
* KASVS vector loaderAlex Stapleton2014-08-101-3/+456
* negative testPaul Kehrer2014-04-301-0/+3
* rename dss_sig_value -> der_encode_dsa_signaturePaul Kehrer2014-04-301-6/+8
* use pyasn1 for creating the dss-sig-value structurePaul Kehrer2014-04-301-11/+0
* dss_sig_value: Pure python conversion of (r, s) to byte streamPaul Kehrer2014-04-301-5/+31
* Fix some typos.Alex Gaynor2014-04-251-1/+1
* fix a coverage miss in the dsa sig vector loaderPaul Kehrer2014-04-221-0/+11
* Modify DSA SigVer loader to be able to load SigGen vectorsMohammed Attia2014-04-221-2/+234
* Add DSA SigVer vectors loaderMohammed Attia2014-04-221-39/+296
* SigVer.rsp loadingAlex Stapleton2014-04-191-4/+7
* Missed an unhexlifyAlex Stapleton2014-04-161-1/+1
* Use binascii.hexlify instead of just hexlifyAlex Stapleton2014-04-151-4/+4
* ECDSA SigGen.{txt,rsp} vector loaderAlex Stapleton2014-04-131-2/+161
* ECDSA vector loaderAlex Stapleton2014-04-121-2/+124
* expand pkcs1 loader to support OAEP as wellPaul Kehrer2014-03-291-0/+214
* Pain the bikeshed a different colourAlex Stapleton2014-03-271-1/+1
* Fixes to @alex's commentsAlex Stapleton2014-03-271-17/+20
* Update testsAlex Stapleton2014-03-271-11/+16
* Address most of my own commentsAlex Stapleton2014-03-271-1/+32
* Move cryptography.vectors to cryptography_vectorsAlex Stapleton2014-03-241-0/+7
* import order fixes for future automated checkingPaul Kehrer2014-03-191-4/+4
* remove a comma that was pointlessly addedPaul Kehrer2014-03-181-1/+1
* add headers to each test so the file source can be determinedPaul Kehrer2014-03-181-1/+11
* another file permutation for rsa nist tested.Paul Kehrer2014-03-181-1/+62
* expand RSA NIST vector loader to support verification vectors as wellPaul Kehrer2014-03-181-4/+75
* change rsa nist loader to use strings for algorithm namePaul Kehrer2014-03-161-3/+3
* Add the vectors for different (L,N) pairs again for the loader testMohammed Attia2014-03-131-108/+246
* Change flag to a boolMohammed Attia2014-03-131-94/+92
* Remove some of the vectors in the loader testMohammed Attia2014-03-121-577/+2
* Use iteritems from the six module for Python 3 compatibilityMohammed Attia2014-03-121-1/+3
* Decrease loader test sizeMohammed Attia2014-03-121-575/+1
* Add loader and loader test for FIPS DSA KeyPair vectorsMohammed Attia2014-03-121-1/+1370
* add FIPS RSA test loader + testsPaul Kehrer2014-03-101-1/+65
* Added future imports and licenses that are missingAlex Gaynor2014-03-081-0/+2
* these examples should be bytes to be consistent with other loadersPaul Kehrer2014-02-191-37/+38
* rename msg -> message in pkcs1 loaderPaul Kehrer2014-02-181-13/+14
* expand pkcs1 loader to load PKCS1 v1.5 and PSS signature examplesPaul Kehrer2014-02-171-8/+125
* remove openssl vector loader that is no longer in usePaul Kehrer2014-02-161-53/+2
* add crt coefficients to RSAPrivateKey constructor and update testsPaul Kehrer2014-02-121-2/+29
* Updated vectors to include secret.Ayrx2014-02-101-0/+16
* Added test vectors for HOTP and TOTP algorithms.Ayrx2014-02-091-0/+98
* PKCS #1 RSA test vector loaderAlex Stapleton2014-02-051-1/+298
* add test for null char replacementPaul Kehrer2014-01-291-0/+19
* revert fixture decorator for now, switch to append. no more globalsPaul Kehrer2014-01-191-8/+8
* modify backend selection to allow multiple backends via comma delimiterPaul Kehrer2014-01-181-5/+26
* support --backend as a pytest flag to limit to one backend for testingPaul Kehrer2014-01-131-1/+22
25%; margin: 0; } td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; } span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; } td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; } .highlight .hll { background-color: #ffffcc } .highlight { background: #ffffff; } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Revision Control Information
 *
 * $Source$
 * $Author$
 * $Revision$
 * $Date$
 *
 */
//#include "port.h"
#include "sparse_int.h"

ABC_NAMESPACE_IMPL_START


/*
 *  free-lists are only used if 'FAST_AND_LOOSE' is set; this is because
 *  we lose the debugging capability of libmm_t which trashes objects when
 *  they are free'd.  However, FAST_AND_LOOSE is much faster if matrices
 *  are created and freed frequently.
 */

#ifdef FAST_AND_LOOSE
sm_element *sm_element_freelist;
sm_row *sm_row_freelist;
sm_col *sm_col_freelist;
#endif


sm_matrix *
sm_alloc()
{
    register sm_matrix *A;

    A = ALLOC(sm_matrix, 1);
    A->rows = NIL(sm_row *);
    A->cols = NIL(sm_col *);
    A->nrows = A->ncols = 0;
    A->rows_size = A->cols_size = 0;
    A->first_row = A->last_row = NIL(sm_row);
    A->first_col = A->last_col = NIL(sm_col);
    A->user_word = NIL(char);        /* for our user ... */
    return A;
}


sm_matrix *
sm_alloc_size(row, col)
int row, col;
{
    register sm_matrix *A;

    A = sm_alloc();
    sm_resize(A, row, col);
    return A;
}


void
sm_free(A)
sm_matrix *A;
{
#ifdef FAST_AND_LOOSE
    register sm_row *prow;

    if (A->first_row != 0) {
    for(prow = A->first_row; prow != 0; prow = prow->next_row) {
        /* add the elements to the free list of elements */
        prow->last_col->next_col = sm_element_freelist;
        sm_element_freelist = prow->first_col;
    }

    /* Add the linked list of rows to the row-free-list */
    A->last_row->next_row = sm_row_freelist;
    sm_row_freelist = A->first_row;

    /* Add the linked list of cols to the col-free-list */
    A->last_col->next_col = sm_col_freelist;
    sm_col_freelist = A->first_col;
    }
#else
    register sm_row *prow, *pnext_row;
    register sm_col *pcol, *pnext_col;

    for(prow = A->first_row; prow != 0; prow = pnext_row) {
    pnext_row = prow->next_row;
    sm_row_free(prow);
    }
    for(pcol = A->first_col; pcol != 0; pcol = pnext_col) {
    pnext_col = pcol->next_col;
    pcol->first_row = pcol->last_row = NIL(sm_element);
    sm_col_free(pcol);
    }
#endif

    /* Free the arrays to map row/col numbers into pointers */
    FREE(A->rows);
    FREE(A->cols);
    FREE(A);
}


sm_matrix *
sm_dup(A)
sm_matrix *A; 
{
    register sm_row *prow;
    register sm_element *p;
    register sm_matrix *B;

    B = sm_alloc();
    if (A->last_row != 0) {
    sm_resize(B, A->last_row->row_num, A->last_col->col_num);
    for(prow = A->first_row; prow != 0; prow = prow->next_row) {
        for(p = prow->first_col; p != 0; p = p->next_col) {
        (void) sm_insert(B, p->row_num, p->col_num);
        }
    }
    }
    return B;
}


void 
sm_resize(A, row, col)
register sm_matrix *A;
int row, col;
{
    register int i, new_size;

    if (row >= A->rows_size) {
    new_size = MAX(A->rows_size*2, row+1);
    A->rows = REALLOC(sm_row *, A->rows, new_size);
    for(i = A->rows_size; i < new_size; i++) {
        A->rows[i] = NIL(sm_row);
    }
    A->rows_size = new_size;
    }

    if (col >= A->cols_size) {
    new_size = MAX(A->cols_size*2, col+1);
    A->cols = REALLOC(sm_col *, A->cols, new_size);
    for(i = A->cols_size; i < new_size; i++) {
        A->cols[i] = NIL(sm_col);
    }
    A->cols_size = new_size;
    }
}


/*  
 *  insert -- insert a value into the matrix
 */
sm_element *
sm_insert(A, row, col)
register sm_matrix *A;
register int row, col;
{
    register sm_row *prow;
    register sm_col *pcol;
    register sm_element *element;
    sm_element *save_element;

    if (row >= A->rows_size || col >= A->cols_size) {
    sm_resize(A, row, col);
    }

    prow = A->rows[row];
    if (prow == NIL(sm_row)) {
    prow = A->rows[row] = sm_row_alloc();
    prow->row_num = row;
    sorted_insert(sm_row, A->first_row, A->last_row, A->nrows, 
            next_row, prev_row, row_num, row, prow);
    }

    pcol = A->cols[col];
    if (pcol == NIL(sm_col)) {
    pcol = A->cols[col] = sm_col_alloc();
    pcol->col_num = col;
    sorted_insert(sm_col, A->first_col, A->last_col, A->ncols, 
            next_col, prev_col, col_num, col, pcol);
    }

    /* get a new item, save its address */
    sm_element_alloc(element);
    save_element = element;

    /* insert it into the row list */
    sorted_insert(sm_element, prow->first_col, prow->last_col, 
        prow->length, next_col, prev_col, col_num, col, element);

    /* if it was used, also insert it into the column list */
    if (element == save_element) {
    sorted_insert(sm_element, pcol->first_row, pcol->last_row, 
        pcol->length, next_row, prev_row, row_num, row, element);
    } else {
    /* otherwise, it was already in matrix -- free element we allocated */
    sm_element_free(save_element);
    }
    return element;
}


sm_element *
sm_find(A, rownum, colnum)
sm_matrix *A;
int rownum, colnum;
{
    sm_row *prow;
    sm_col *pcol;

    prow = sm_get_row(A, rownum);
    if (prow == NIL(sm_row)) {
    return NIL(sm_element);
    } else {
    pcol = sm_get_col(A, colnum);