Exemple #1
0
static void
mppe_key_change(mppe *_mppe, mppe_rc4_t *_this)
{
	u_char interim[16];
	void *keychg;

	keychg = rc4_create_ctx();

	GetNewKeyFromSHA(_this->master_key, _this->session_key,
	    _this->keylen, interim);

	rc4_key(keychg, _this->keylen, interim);
	rc4(keychg, _this->keylen, interim, _this->session_key);
	mppe_reduce_key(_this);

	if (_this->old_session_keys) {
		int idx = _this->coher_cnt % MPPE_NOLDKEY;
		memcpy(_this->old_session_keys[idx],
		    _this->session_key, MPPE_KEYLEN);
	}

	free(keychg);
}
Exemple #2
0
SECURITY_STATUS
SspMapContext(
    IN PCtxtHandle  phContext,
    IN PUCHAR       pSessionKey,
    IN ULONG        NegotiateFlags,
    IN HANDLE       TokenHandle,
    IN LPWSTR       ContextNames,
    IN PTimeStamp   PasswordExpiry OPTIONAL
    )

/*++

RoutineDescription:

    Create a local context for a real context

Arguments:

Return Value:

--*/

{
    SECURITY_STATUS scRet = SEC_E_OK;
    PCheaterContext pContext;


    pContext = SspAddLocalContext(
                    phContext,
                    pSessionKey,
                    NegotiateFlags,
                    TokenHandle,
                    ContextNames );

    if (pContext)
    {
        if (ARGUMENT_PRESENT(PasswordExpiry))
        {
            pContext->PasswordExpiry = *PasswordExpiry;
        }
        else
        {
            pContext->PasswordExpiry.QuadPart = 0;
        }
        pContext->Nonce = 0;
#ifndef EXPORT_BUILD
        if ((NegotiateFlags & NTLMSSP_NEGOTIATE_STRONG_CRYPT) != 0) {
            rc4_key(&pContext->Rc4Key, MSV1_0_USER_SESSION_KEY_LENGTH, pContext->SessionKey);

        } else
#endif
        if (NegotiateFlags & NTLMSSP_NEGOTIATE_LM_KEY)
        {
            UCHAR Key[MSV1_0_LANMAN_SESSION_KEY_LENGTH];

            ASSERT(MSV1_0_LANMAN_SESSION_KEY_LENGTH == 8);

            RtlCopyMemory(Key,pContext->SessionKey,5);

            //
            // Put a well-known salt at the end of the key to
            // limit the changing part to 40 bits.
            //

            Key[5] = 0xe5;
            Key[6] = 0x38;
            Key[7] = 0xb0;

            rc4_key(&pContext->Rc4Key, MSV1_0_LANMAN_SESSION_KEY_LENGTH, Key);
        } else {
            rc4_key(&pContext->Rc4Key, MSV1_0_USER_SESSION_KEY_LENGTH, pContext->SessionKey);
        }
    }
    else scRet = SEC_E_INVALID_HANDLE;

    return(scRet);
}
Exemple #3
0
static int
mppe_rc4_setoldkey(mppe *_mppe, mppe_rc4_t *_this, uint16_t coher_cnt)
{
	return rc4_key(_this->rc4ctx, _this->keylen,
	    _this->old_session_keys[coher_cnt % MPPE_NOLDKEY]);
}
Exemple #4
0
static int
mppe_rc4_setkey(mppe *_mppe, mppe_rc4_t *_this)
{
	return rc4_key(_this->rc4ctx, _this->keylen, _this->session_key);
}
Exemple #5
0
int _cdecl main(int argc, char **argv)
{
    struct RC4_KEYSTRUCT    KeyContext;
    BYTE                    Buffer[sizeof(Plaintext)];

    printf("=================== RC4 Unit Test ==================\n");
    
    //
    // Test Key-Scheduling Algorithm (KSA)
    //

    printf("Key-Scheduling Algorithm (KSA) ...\t\t");

    rc4_key(&KeyContext, sizeof(Key), Key);

#if 0
    // ==
        printf("\n");
        for (i = 0; i < 256; i++)
        {
            printf("0x%02X, ", KeyContext.S[i]);
            if ((i + 1) % 8 == 0) printf("\n");
        }
        printf("\n");
    // ==
#endif

    if (memcmp(KeyContext.S, KeystreamResult, sizeof(KeystreamResult)) != 0)
    {
        printf("FAIL\n");
        return 1;
    }
    else
        printf("SUCC\n");

    //
    // Test Pseudo-Random Generation Algorithm (PRGA)
    //

    printf("Pseudo-Random Generation Algorithm (PRGA) ...\t");

    memcpy(Buffer, Plaintext, sizeof(Plaintext));
    rc4(&KeyContext, sizeof(Buffer), Buffer);

#if 0
        // ==
            printf("\n");
            for (i = 0; i < sizeof(Buffer); i++)
            {
                printf("0x%02X, ", Buffer[i]);
                if ((i + 1) % 8 == 0) printf("\n");
            }
            printf("\n");
        // ==
#endif

    if (memcmp(Buffer, CiphertextResult, sizeof(CiphertextResult)) != 0)
    {
        printf("FAIL\n");
        return 1;
    }
    else
        printf("SUCC\n");
    
    printf("====================================================\n");

    return 0;
}