43 assert(
isWritePtr( dataPtrPtr,
sizeof(
void * ) ) );
47 REQUIRES( dataLength > 0 || dataLength < stell( stream ) );
54 return( sMemGetDataBlockAbs( stream, position, dataPtrPtr, dataLength ) );
62 int openPacketStreamSSH(
OUT STREAM *stream,
66 const int packetType )
74 sMemOpen( stream, sessionInfoPtr->sendBuffer,
77 return( sputc( stream, packetType ) );
81 int openPacketStreamSSHEx(
OUT STREAM *stream,
86 const int packetType )
92 assert(
isWritePtr( sessionInfoPtr->sendBuffer, streamSize ) );
97 REQUIRES( streamSize > SSH2_HEADER_SIZE && \
100 sMemOpen( stream, sessionInfoPtr->sendBuffer, streamSize );
101 swrite( stream,
"\x00\x00\x00\x00\x00", SSH2_HEADER_SIZE );
102 return( sputc( stream, packetType ) );
109 const int packetType,
112 const int offset = stell( stream );
116 assert(
isWritePtr( packetOffset,
sizeof(
int ) ) );
121 ( stell( stream ) > SSH2_HEADER_SIZE + 1 && \
127 swrite( stream,
"\x00\x00\x00\x00\x00", SSH2_HEADER_SIZE );
128 status = sputc( stream, packetType );
167 int length = stell( stream ) -
offset;
169 const int padBlockSize =
max( sessionInfoPtr->cryptBlocksize, 8 );
171 const int extraLength = \
173 sessionInfoPtr->authBlocksize : 0;
174 int padLength, status;
182 REQUIRES( payloadLength >= 0 && payloadLength < length && \
183 offset + length + extraLength <= sessionInfoPtr->sendBufSize );
190 if( useQuantisedPadding )
195 for( padLength = 256;
209 status = sMemGetDataBlockAbs( stream, offset, &bufStartPtr,
210 length + extraLength );
213 DEBUG_DIAG((
"Not enough room for padding and MAC in data block" ));
225 if( isWriteableStream )
227 sseek( stream, offset );
228 writeUint32( stream, 1 + payloadLength + padLength );
229 status = sputc( stream, padLength );
231 status = sSkip( stream, payloadLength );
241 stell( stream ) == SSH2_HEADER_SIZE + payloadLength );
242 sMemOpen( &headerStream, bufStartPtr, SSH2_HEADER_SIZE );
243 writeUint32( &headerStream, 1 + payloadLength + padLength );
244 status = sputc( &headerStream, padLength );
245 sMemDisconnect( &headerStream );
248 DEBUG_PRINT((
"Wrote %s (%d) packet, length %d.\n",
257 BYTE padding[ 256 + 8 ];
262 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
263 if( isWriteableStream )
264 status = swrite( stream, padding, padLength );
269 REQUIRES( stell( stream ) == length - padLength );
270 sMemOpen( &trailerStream,
271 (
BYTE * ) bufStartPtr + ( length - padLength ),
273 status = swrite( &trailerStream, padding, padLength );
274 sMemDisconnect( &trailerStream );
276 status = sSkip( stream, padLength );
283 status = createMacSSH( sessionInfoPtr->iAuthOutContext,
290 status = sSkip( stream, sessionInfoPtr->authBlocksize );
302 BYTE padding[ 256 + 8 ];
307 memset( padding, 0, padLength );
308 status = swrite( stream, padding, padLength );
331 status = wrapPacketSSH2( sessionInfoPtr, stream, 0,
FALSE,
TRUE );
337 length = stell( stream );
338 status = sMemGetDataBlockAbs( stream, 0, &dataPtr, length );
342 status = swrite( &sessionInfoPtr->stream, dataPtr, length );
346 sNetGetErrorInfo( &sessionInfoPtr->stream,
347 &sessionInfoPtr->errorInfo );