Example #1
0
int CREDLIB_mod_hash( BIGNUM* r, BIGNUM* n, BIGNUM* n2,
                      byte* out, int out_len, BIGNUM* m, BN_CTX* ctx ) {
    EXCEPTION;
    SHA_CTX sha1;
    byte hash[ SHA_DIGEST_LENGTH ];
    byte* dat = NULL;
    int dat_len_s, req_len, alt_len;
    int* dat_len=&dat_len_s;
 
    if ( !m || !r || !ctx ) { THROW( CREDLIB_NULL_PTR ); }
    if ( !n && !n2 && !out ) { THROW( CREDLIB_NULL_PTR ); } /* no input! */
 
    SHA1_Init( &sha1 );
 
    req_len = ( n ? CREDLIB_calc_bn( n ) : 0 )
        + ( n2 ? CREDLIB_calc_bn( n2 ) : 0 );
 
    if ( req_len > 0 ) {
        TRY( CREDLIB_out( &dat, &dat_len, &alt_len, req_len ) );
        TRYIO_start( dat );
        /* use serialization system to n||n2 to prevent ambiguity */
        if ( n ) { TRYIO( CREDLIB_write_bn( ptr, n ) ); }
        if ( n2 ) { TRYIO( CREDLIB_write_bn( ptr, n2 ) ); }
 
        SHA1_Update( &sha1, dat, TRYIO_len( dat ) );
    }
    if ( out ) { SHA1_Update( &sha1, out, out_len ); }
    SHA1_Final( hash, &sha1 );
     
    CREDLIB_free( dat );
    TRYM( BN_bin2bn( hash, SHA_DIGEST_LENGTH, r ) );
    TRYM( BN_mod( r, r, m, ctx ) );
     
 cleanup:
    return ret;
}
Example #2
0
int CREDLIB_out( byte** msg, int** msg_len, 
		 int* alt_len, int required_len ) {
    EXCEPTION;
    
    if ( !msg || !msg_len || !alt_len ) { THROW( CREDLIB_NULL_PTR ); }
    if ( !*msg_len ) { *msg_len = alt_len; **msg_len = required_len; }
    if ( *msg ) {
	if ( **msg_len < required_len ) {
	    THROW( CREDLIB_ARG_TOO_SMALL );
	}
    } else {
	TRYM( *msg = CREDLIB_malloc( required_len ) );
	**msg_len = required_len;
    }
 cleanup:
    return ret;
}
Example #3
0
int CREDLIB_read_bn_array( const byte* in, BIGNUM*** bnap, int* bna_len,
			   int off ) {
    EXCEPTION;
    int alt_len, req_len, i;
    BIGNUM** bna = NULL;

    if ( !in || !bnap || !bna_len ) { THROW( CREDLIB_NULL_PTR ); }

    TRYIO_start( in );
    TRYIO( CREDLIB_read_uint16( ptr, req_len ) );
    if ( !bna_len ) { bna_len = &alt_len; alt_len = req_len; }
    if ( !*bnap ) { 
	TRYM( *bnap = CREDLIB_BN_array_malloc( req_len+off ) ); 
	*bna_len = req_len+off;
    }
    bna = *bnap;
    for ( i = off; i < *bna_len; i++ ) {
	TRYIO( CREDLIB_read_bn( ptr, &(bna[i]) ) );
    }
    RETURN( TRYIO_len( in ) );
 cleanup:
    return ret;
}
Example #4
0
dcpu16token nexttoken() {
#define return_(x) /*printf("%d:%s\n", curline, #x);*/ return x;
    /* Skip all spaces TO the next token */
    while (isspace(*cur_pos))
        cur_pos++;

    /* Test some operators */
    switch (*cur_pos++) {
    case '\0':
    case '\n': return_(T_NEWLINE);
    case ',': return_(T_COMMA);
    case '[': return_(T_LBRACK);
    case ']': return_(T_RBRACK);
    case '+': return_(T_PLUS);
    case ':': return_(T_COLON);
    case '\"': return parsestring(&cur_pos);
    default: break;
    }

    cur_pos--;

#define TRY(i) if (!strncasecmp(cur_pos, #i, strlen(#i))) {     \
    if (!isalnum(*(cur_pos + strlen(#i)))) {                    \
        cur_pos += strlen(#i);                                  \
        return_(T_ ## i);                                       \
    }                                                           \
}

#define TRYM(i) if (!strncasecmp(cur_pos, "." #i, strlen(#i) + 1)) { \
    cur_pos += strlen(#i) + 1;                                       \
    return_(T_ ## i);                                                \
}

    /* Try assembler pseudo instructions */
    TRYM(ORG); TRYM(DAT);

    /* Try instructions */
    TRY(SET); TRY(ADD); TRY(SUB); TRY(MUL); TRY(DIV); TRY(MOD); TRY(SHL);
    TRY(SHR); TRY(AND); TRY(BOR); TRY(XOR); TRY(IFE); TRY(IFN); TRY(IFG);
    TRY(IFB); TRY(JSR);

    /* Compatibility for other assemblers */
    TRY(DAT); TRY(ORG);

    /* And some "special" registers */
    TRY(POP); TRY(PEEK); TRY(PUSH); TRY(SP); TRY(PC); TRY(O);

#undef TRY
#undef TRYM

    if (isalpha(*cur_pos)) {
        int strlength = 0;

        /* Register or label */
        while (isalnum(*cur_pos) || (*cur_pos == '_')) {
            cur_pos++;
            strlength++;
        }

        if (strlength > 1) {
            strncpy(cur_tok.string, cur_pos - strlength, strlength);
            cur_tok.string[strlength] = '\0';

            return_(T_IDENTIFIER);
        } else {
            return parseregister(*(cur_pos - strlength));
        }
    } else if (isdigit(*cur_pos)) {
        cur_tok.number = parsenumeric();

        return_(T_NUMBER);
    }

    error("Unrecognized input '%c'", *cur_pos);
    return T_NEWLINE;
#undef return_
}