30 #if defined( INC_ALL )
50 assert(
isWritePtr( keySize,
sizeof(
int ) ) );
51 assert( (
isReadPtr( keyData, keyDataLength ) && \
53 ( keyData == NULL && keyDataLength == 0 && \
55 ( keyData == NULL && keyDataLength == 0 && \
60 keyDataLength > 0 && \
63 ( keyData == NULL && keyDataLength == 0 && \
65 ( keyData == NULL && keyDataLength == 0 && \
97 const int actualKeySize = \
99 ( requestedKeySize < 128 + 8 ) ?
bitsToBytes( 1024 ) : \
100 ( requestedKeySize < 192 + 8 ) ?
bitsToBytes( 1536 ) : \
101 ( requestedKeySize < 256 + 8 ) ?
bitsToBytes( 2048 ) : \
102 ( requestedKeySize < 384 + 8 ) ?
bitsToBytes( 3072 ) : \
124 switch( actualKeySize )
127 keyData = dh1024SPKI;
128 keyLength =
sizeof( dh1024SPKI );
129 keyType = CRYPT_IATTRIBUTE_KEY_SPKI;
134 keyLength = sizeof( dh1536SSH );
139 keyLength = sizeof( dh2048SSH );
145 keyLength = sizeof( dh3072SSH );
157 DEBUG_DIAG((
"Couldn't create DH context from stored data" ));
162 *iCryptContext = iDHContext;
176 #error SSH with ECC support requires USE_SSL to be defined
204 assert(
isWritePtr( keySize,
sizeof(
int ) ) );
234 keyData = ecdh256SSL;
239 keyData = ecdh384SSL;
244 keyData = ecdh521SSL;
253 CRYPT_IATTRIBUTE_KEY_SSL );
263 *iCryptContext = iECDHContext;
281 IN_RANGE( 1, 4 )
const int nonceLen,
297 REQUIRES( attributeSize >= 8 && attributeSize <= 40 );
299 REQUIRES( hashSize == 20 || hashSize == 32 );
300 REQUIRES( nonceLen >= 1 && nonceLen <= 4 );
304 memcpy( hashInfo, initialHashInfo,
sizeof(
HASHINFO ) );
308 if( attributeSize > hashSize )
318 memcpy( hashInfo, initialHashInfo,
sizeof(
HASHINFO ) );
328 &msgData, attribute );
349 sessionInfoPtr->iCryptInContext = createInfo.
cryptHandle;
357 sessionInfoPtr->iCryptOutContext = createInfo.
cryptHandle;
363 if(
cryptStatusOK( status ) && sessionInfoPtr->version == 1 && \
382 if( sessionInfoPtr->version == 2 )
392 sessionInfoPtr->iAuthInContext = createInfo.
cryptHandle;
394 sessionInfoPtr->integrityAlgo );
401 sessionInfoPtr->iAuthOutContext = createInfo.
cryptHandle;
404 &sessionInfoPtr->authBlocksize,
412 destroySecurityContextsSSH( sessionInfoPtr );
423 if( sessionInfoPtr->iKeyexCryptContext !=
CRYPT_ERROR )
429 if( sessionInfoPtr->iCryptInContext !=
CRYPT_ERROR )
435 if( sessionInfoPtr->iCryptOutContext !=
CRYPT_ERROR )
441 if( sessionInfoPtr->iAuthInContext !=
CRYPT_ERROR )
447 if( sessionInfoPtr->iAuthOutContext !=
CRYPT_ERROR )
470 status = initSecurityContextsSSH( sessionInfoPtr );
513 getHashParameters( handshakeInfo->exchangeHashAlgo, 0, &hashFunction,
520 hashFunction( initialHashInfo, NULL, 0, handshakeInfo->sessionID,
526 BYTE header[ 8 + 8 ];
527 const int mpiLength = ( handshakeInfo->secretValue[ 0 ] & 0x80 ) ? \
528 handshakeInfo->secretValueLength + 1 : \
529 handshakeInfo->secretValueLength;
535 sMemOpen( &stream, header, 8 );
536 status = writeUint32( &stream, mpiLength );
537 if( handshakeInfo->secretValue[ 0 ] & 0x80 )
540 status = sputc( &stream, 0 );
544 sMemDisconnect( &stream );
549 hashFunction( initialHashInfo, NULL, 0, handshakeInfo->secretValue,
551 hashFunction( initialHashInfo, NULL, 0, handshakeInfo->sessionID,
568 status = loadCryptovariable( isClient ? \
569 sessionInfoPtr->iCryptOutContext : \
570 sessionInfoPtr->iCryptInContext,
572 hashFunction, hashSize,
573 initialHashInfo,
"A", 1,
574 handshakeInfo->sessionID,
575 handshakeInfo->sessionIDlength );
577 status = loadCryptovariable( isClient ? \
578 sessionInfoPtr->iCryptInContext : \
579 sessionInfoPtr->iCryptOutContext,
581 hashFunction, hashSize,
582 initialHashInfo,
"B", 1,
583 handshakeInfo->sessionID,
584 handshakeInfo->sessionIDlength );
587 status = loadCryptovariable( isClient ? \
588 sessionInfoPtr->iCryptOutContext : \
589 sessionInfoPtr->iCryptInContext,
591 hashFunction, hashSize,
592 initialHashInfo,
"C", 1,
593 handshakeInfo->sessionID,
594 handshakeInfo->sessionIDlength );
596 status = loadCryptovariable( isClient ? \
597 sessionInfoPtr->iCryptInContext : \
598 sessionInfoPtr->iCryptOutContext,
600 hashFunction, hashSize,
601 initialHashInfo,
"D", 1,
602 handshakeInfo->sessionID,
603 handshakeInfo->sessionIDlength );
605 status = loadCryptovariable( isClient ? \
606 sessionInfoPtr->iAuthOutContext : \
607 sessionInfoPtr->iAuthInContext,
609 ( sessionInfoPtr->protocolFlags & \
612 sessionInfoPtr->authBlocksize,
613 hashFunction, hashSize,
614 initialHashInfo,
"E", 1,
615 handshakeInfo->sessionID,
616 handshakeInfo->sessionIDlength );
618 status = loadCryptovariable( isClient ? \
619 sessionInfoPtr->iAuthInContext : \
620 sessionInfoPtr->iAuthOutContext,
622 ( sessionInfoPtr->protocolFlags & \
625 sessionInfoPtr->authBlocksize,
626 hashFunction, hashSize,
627 initialHashInfo,
"F", 1,
628 handshakeInfo->sessionID,
629 handshakeInfo->sessionIDlength );
648 BYTE buffer[ 128 + 8 ];
659 sMemOpen( &stream, buffer, 128 );
660 status = writeUint32( &stream, dataLength );
661 if(
cryptStatusOK( status ) && dataLength <= sMemDataLeft( &stream ) )
665 status = swrite( &stream, data, dataLength );
666 copiedToBuffer =
TRUE;
670 buffer, stell( &stream ) );
677 sMemClose( &stream );
690 BYTE buffer[ 8 + 8 ];
691 const int length = ( data[ 0 ] & 0x80 ) ? dataLength + 1 : dataLength;
701 sMemOpen( &stream, buffer, 8 );
702 status = writeUint32( &stream, length );
703 if( data[ 0 ] & 0x80 )
706 status = sputc( &stream, 0 );
709 headerLength = stell( &stream );
710 sMemDisconnect( &stream );
714 buffer, headerLength );
739 assert( ( data == NULL && dataLength == 0 ) || \
745 seqNo >= 2 && seqNo < INT_MAX ) );
749 REQUIRES( ( data == NULL && dataLength == 0 ) || \
774 BYTE headerBuffer[ 16 + 8 ];
775 int length = ( macType ==
MAC_NONE ) ? dataLength : packetDataLength;
779 ( macType ==
MAC_START && packetDataLength >= dataLength ) );
788 sMemOpen( &stream, headerBuffer, 16 );
789 writeUint32( &stream, seqNo );
790 status = writeUint32( &stream, length );
792 headerLength = stell( &stream );
793 sMemDisconnect( &stream );
799 headerBuffer, headerLength );
833 assert(
isReadPtr( data, dataMaxLength ) );
838 seqNo >= 2 && seqNo < INT_MAX ) );
852 dataMaxLength == dataLength ) || \
854 dataLength + macLength <= dataMaxLength ) );
860 if( dataLength <= 0 )
862 status = macDataSSH( iMacContext, seqNo, NULL, 0,
863 packetDataLength, macType );
867 status = macDataSSH( iMacContext, seqNo, data, dataLength,
868 packetDataLength, macType );
894 assert(
isReadPtr( data, dataMaxLength ) );
897 REQUIRES( seqNo >= 2 && seqNo < INT_MAX );
904 REQUIRES( dataLength + macLength <= dataMaxLength );
910 if( dataLength <= 0 )
911 status = macDataSSH( iMacContext, seqNo, NULL, 0, 0,
MAC_NONE );
913 status = macDataSSH( iMacContext, seqNo, data, dataLength, 0,
MAC_NONE );
937 REQUIRES( seqNo >= 2 && seqNo < INT_MAX );
942 REQUIRES( dataLength > 0 && dataLength < dataMaxLength && \
946 status = macDataSSH( iMacContext, seqNo, data, dataLength, 0,
MAC_NONE );
957 memcpy( data + dataLength, mac, msgData.
length );
989 sMemConnect( &stream, handshakeInfo->clientKeyexValue,
990 handshakeInfo->clientKeyexValueLength );
992 sMemConnect( &stream, handshakeInfo->serverKeyexValue,
993 handshakeInfo->serverKeyexValueLength );
994 if( handshakeInfo->isECDH )
999 status = readInteger32( &stream, keyAgreeParams.publicValue,
1005 status = readInteger32( &stream, keyAgreeParams.publicValue,
1009 sMemDisconnect( &stream );
1012 if( handshakeInfo->isECDH )
1015 handshakeInfo->serverKeySize, 0 ) )
1021 handshakeInfo->serverKeySize, 0 ) )
1029 "Invalid %s phase 1 MPI",
1030 handshakeInfo->isECDH ?
"ECDH" :
"DH" ) );
1039 const int xCoordLen = ( keyAgreeParams.
wrappedKeyLen - 1 ) / 2;
1054 keyAgreeParams.wrappedKey[ 0 ] == 0x04 );
1055 memmove( keyAgreeParams.wrappedKey,
1056 keyAgreeParams.wrappedKey + 1, xCoordLen );
1063 memcpy( handshakeInfo->secretValue, keyAgreeParams.wrappedKey,
1065 handshakeInfo->secretValueLength = keyAgreeParams.
wrappedKeyLen;
1076 if( handshakeInfo->requestedServerKeySize > 0 )
1083 handshakeInfo->encodedReqKeySizes,
1084 handshakeInfo->encodedReqKeySizesLength );
1091 CRYPT_IATTRIBUTE_KEY_SSH );
1096 keyexBuffer + extraLength,
1097 msgData.
length - extraLength );
1106 handshakeInfo->clientKeyexValue,
1107 handshakeInfo->clientKeyexValueLength );
1111 handshakeInfo->serverKeyexValue,
1112 handshakeInfo->serverKeyexValueLength );
1114 status = hashAsMPI( handshakeInfo->iExchangeHashContext,
1115 handshakeInfo->secretValue,
1116 handshakeInfo->secretValueLength );
1158 handshakeInfo->sessionIDlength = msgData.
length;
1170 !
isEccAlgo( handshakeInfo->pubkeyAlgo ) )
1172 const CRYPT_CONTEXT tempContext = handshakeInfo->iExchangeHashContext;
1174 handshakeInfo->iExchangeHashContext = \
1175 handshakeInfo->iExchangeHashAltContext;
1176 handshakeInfo->iExchangeHashAltContext = tempContext;
1183 handshakeInfo->sessionIDlength );