Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packing and unpacking vector of NTL polynomials #1593

Open
sknc opened this issue Feb 23, 2025 · 2 comments
Open

Packing and unpacking vector of NTL polynomials #1593

sknc opened this issue Feb 23, 2025 · 2 comments

Comments

@sknc
Copy link

sknc commented Feb 23, 2025

Hello Marcel,

I am creating a data type that uses a vector of NTL::GF2X polynomials named value and am trying to figure out how to pack and unpack it. I came up with the following. Does it seem along the right lines? (BTW, modulus is the polynomial used to initialize the GF2E I am using.)

void pack(octetStream& stream) {
        stream.store(value.length());
        size_t numBytes = deg(modulus) + 1;
        for(auto& poly: value) {
            unsigned char* c;
            NTL::BytesFromGF2X(c, poly, numBytes);
            stream.store_bytes(c, numBytes);
        }
}
void unpack(octetStream& stream) {
        long len;
        stream.get(len);
        size_t numBytes = deg(modulus) + 1;
        for(long i = 0; i < len; i++) {
            unsigned char* c;
            stream.get_bytes(c, numBytes);
            NTL::GF2XFromBytes(value[i], c, numBytes);
        }
}
@mkskeller
Copy link
Member

I don't the NTL function but you cannot use unallocated pointers, that is, you need to allocate some memory for c to point at. See the following for an introduction: https://cplusplus.com/doc/tutorial/dynamic/

@sknc
Copy link
Author

sknc commented Feb 24, 2025

The NTL functions convert a polynomial in NTL::GF2X to a byte array and vice versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants