Skip to content

Modular exponentiation returns 1 if exponent is 0 and modulo is 1 #185

@guidovranken

Description

@guidovranken

I think any calculation MOD 1 should always return 0, or is this a special case?

#include <relic_conf.h>
#include <relic.h>

int main(void)
{
    if ( core_init() != RLC_OK ) abort();

    bn_t A, B, C, R;

    bn_null(A); bn_new(A);
    bn_null(B); bn_new(B);
    bn_null(C); bn_new(C);
    bn_null(R); bn_new(R);

    {
        const char* s = "1";
        /* noret */ bn_read_str(A, s, strlen(s), 10);
    }
    {
        const char* s = "0";
        /* noret */ bn_read_str(B, s, strlen(s), 10);
    }
    {
        const char* s = "1";
        /* noret */ bn_read_str(C, s, strlen(s), 10);
    }

    /* noret */ bn_mxp(R, A, B, C);

    int outsize = bn_size_str(R, 10);
    char* s2 = malloc(outsize);
    /* noret */ bn_write_str(s2, outsize, R, 10);
    printf("%s\n", s2);
    free(s2);

    bn_free(A);
    bn_free(B);
    bn_free(C);
    bn_free(R);
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions