Exemplo n.º 1
0
void ZIDCacheFile::createZIDFile(char* name) {
    zidFile = fopen(name, "wb+");
    // New file, generate an associated random ZID and save
    // it as first record
    if (zidFile != NULL) {
        randomZRTP(associatedZid, IDENTIFIER_LEN);

        ZIDRecordFile rec;
        rec.setZid(associatedZid);
        rec.setOwnZIDRecord();
        fseek(zidFile, 0L, SEEK_SET);
        if (fwrite(rec.getRecordData(), rec.getRecordLength(), 1, zidFile) < 1)
            ++errors;
        fflush(zidFile);
    }
}
Exemplo n.º 2
0
ZrtpDH::ZrtpDH(const char* type) {

    uint8_t random[64];

    dhCtx* tmpCtx = new dhCtx;
    ctx = static_cast<void*>(tmpCtx);

    // Well - the algo type is only 4 char thus cast to int32 and compare
    if (*(int32_t*)type == *(int32_t*)dh2k) {
        pkType = DH2K;
    }
    else if (*(int32_t*)type == *(int32_t*)dh3k) {
        pkType = DH3K;
    }
    else if (*(int32_t*)type == *(int32_t*)ec25) {
        pkType = EC25;
    }
    else if (*(int32_t*)type == *(int32_t*)ec38) {
        pkType = EC38;
    }
    else if (*(int32_t*)type == *(int32_t*)e255) {
        pkType = E255;
    }
    else if (*(int32_t*)type == *(int32_t*)e414) {
        pkType = E414;
    }
    else {
        return;
    }

    randomZRTP(random, sizeof(random));

    if (!dhinit) {
        bnBegin(&two);
        bnSetQ(&two, 2);

        bnBegin(&bnP2048);
        bnInsertBigBytes(&bnP2048, P2048, 0, sizeof(P2048));
        bnBegin(&bnP3072);
        bnInsertBigBytes(&bnP3072, P3072, 0, sizeof(P3072));

        bnBegin(&bnP2048MinusOne);
        bnCopy(&bnP2048MinusOne, &bnP2048);
        bnSubQ(&bnP2048MinusOne, 1);

        bnBegin(&bnP3072MinusOne);
        bnCopy(&bnP3072MinusOne, &bnP3072);
        bnSubQ(&bnP3072MinusOne, 1);

        dhinit = 1;
    }

    bnBegin(&tmpCtx->privKey);
    INIT_EC_POINT(&tmpCtx->pubPoint);

    switch (pkType) {
    case DH2K:
    case DH3K:
        bnInsertBigBytes(&tmpCtx->privKey, random, 0, 256/8);
        break;

    case EC25:
        ecGetCurveNistECp(NIST256P, &tmpCtx->curve);
        ecGenerateRandomNumber(&tmpCtx->curve, &tmpCtx->privKey);
        break;

    case EC38:
        ecGetCurveNistECp(NIST384P, &tmpCtx->curve);
        ecGenerateRandomNumber(&tmpCtx->curve, &tmpCtx->privKey);
        break;

    case E255:
        ecGetCurvesCurve(Curve25519, &tmpCtx->curve);
        ecGenerateRandomNumber(&tmpCtx->curve, &tmpCtx->privKey);
        break;

    case E414:
        ecGetCurvesCurve(Curve3617, &tmpCtx->curve);
        ecGenerateRandomNumber(&tmpCtx->curve, &tmpCtx->privKey);
        break;
    }
}