Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
if (rv != AEP_R_OK)
goto end;
aep_app_conn_table[count].conn_state = NotConnected;
aep_app_conn_table[count].conn_hndl = 0;
break;
}
}
end:
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
return rv;
}
static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use)
{
int count;
AEP_RV rv = AEP_R_OK;
*in_use = 0;
if (use_engine_lock) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
{
switch (aep_app_conn_table[count].conn_state)
{
case Connected:
rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
if (rv != AEP_R_OK)
goto end;
aep_app_conn_table[count].conn_state = NotConnected;
aep_app_conn_table[count].conn_hndl = 0;
break;
case InUse:
(*in_use)++;
break;
case NotConnected:
break;
}
}
end:
if (use_engine_lock) CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
return rv;
}
/*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums.
Note only 32bit Openssl build support*/
static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize)
{
BIGNUM* bn;
/*Cast the ArbBigNum pointer to our BIGNUM struct*/
bn = (BIGNUM*) ArbBigNum;
#ifdef SIXTY_FOUR_BIT_LONG
*BigNumSize = bn->top << 3;
#else
/*Size of the bignum in bytes is equal to the bn->top (no of 32 bit
words) multiplies by 4*/
*BigNumSize = bn->top << 2;
#endif
return AEP_R_OK;
}
static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
unsigned char* AEP_BigNum)
{
BIGNUM* bn;
#ifndef SIXTY_FOUR_BIT_LONG
unsigned char* buf;
int i;
#endif
/*Cast the ArbBigNum pointer to our BIGNUM struct*/
bn = (BIGNUM*) ArbBigNum;
#ifdef SIXTY_FOUR_BIT_LONG
memcpy(AEP_BigNum, bn->d, BigNumSize);
#else
/*Must copy data into a (monotone) least significant byte first format
performing endian conversion if necessary*/
for(i=0;i<bn->top;i++)
{
buf = (unsigned char*)&bn->d[i];
*((AEP_U32*)AEP_BigNum) = (AEP_U32)
((unsigned) buf[1] << 8 | buf[0]) |
((unsigned) buf[3] << 8 | buf[2]) << 16;
AEP_BigNum += 4;
}
#endif
return AEP_R_OK;
}
/*Turn an AEP Big Num back to a user big num*/
static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
unsigned char* AEP_BigNum)
{
BIGNUM* bn;
#ifndef SIXTY_FOUR_BIT_LONG
int i;
#endif
bn = (BIGNUM*)ArbBigNum;
/*Expand the result bn so that it can hold our big num.
Size is in bits*/
bn_expand(bn, (int)(BigNumSize << 3));
#ifdef SIXTY_FOUR_BIT_LONG
bn->top = BigNumSize >> 3;
if((BigNumSize & 7) != 0)
bn->top++;
memset(bn->d, 0, bn->top << 3);
memcpy(bn->d, AEP_BigNum, BigNumSize);
#else
bn->top = BigNumSize >> 2;
for(i=0;i<bn->top;i++)
{
bn->d[i] = (AEP_U32)
((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 |
((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]);
AEP_BigNum += 4;
}
#endif
return AEP_R_OK;
}
#endif /* !OPENSSL_NO_HW_AEP */
#endif /* !OPENSSL_NO_HW */