/** This function must be called to initialize a digest calculation to be subsequently performed using the EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal(). @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. @retval EFI_SUCCESS Initialized successfully. @retval EFI_INVALID_PARAMETER This is NULL. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver or HashAlgorithm is Null. @retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource. @retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(), or HashInit() is already called before and not terminated by HashFinal() yet on the same instance. **/ EFI_STATUS EFIAPI BaseCrypto2HashInit ( IN CONST EFI_HASH2_PROTOCOL *This, IN CONST EFI_GUID *HashAlgorithm ) { EFI_HASH_INFO *HashInfo; VOID *HashCtx; UINTN CtxSize; BOOLEAN Ret; HASH2_INSTANCE_DATA *Instance; if (This == NULL) { return EFI_INVALID_PARAMETER; } if (HashAlgorithm == NULL) { return EFI_UNSUPPORTED; } HashInfo = GetHashInfo (HashAlgorithm); if (HashInfo == NULL) { return EFI_UNSUPPORTED; } // // Consistency Check // Instance = HASH2_INSTANCE_DATA_FROM_THIS(This); if ((Instance->HashContext != NULL) || (Instance->HashInfoContext != HashInfo)) { return EFI_ALREADY_STARTED; } // // Start hash sequence // CtxSize = HashInfo->GetContextSize (); if (CtxSize == 0) { return EFI_UNSUPPORTED; } HashCtx = AllocatePool (CtxSize); if (HashCtx == NULL) { return EFI_OUT_OF_RESOURCES; } Ret = HashInfo->Init (HashCtx); if (!Ret) { FreePool (HashCtx); return EFI_OUT_OF_RESOURCES; } // // Setup the context // Instance->HashContext = HashCtx; Instance->HashInfoContext = HashInfo; return EFI_SUCCESS; }
/** Returns the size of the hash which results from a specific algorithm. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. @param[out] HashSize Holds the returned size of the algorithm's hash. @retval EFI_SUCCESS Hash size returned successfully. @retval EFI_INVALID_PARAMETER This or HashSize is NULL. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver or HashAlgorithm is null. **/ EFI_STATUS EFIAPI BaseCrypto2GetHashSize ( IN CONST EFI_HASH2_PROTOCOL *This, IN CONST EFI_GUID *HashAlgorithm, OUT UINTN *HashSize ) { EFI_HASH_INFO *HashInfo; if ((This == NULL) || (HashSize == NULL)) { return EFI_INVALID_PARAMETER; } if (HashAlgorithm == NULL) { return EFI_UNSUPPORTED; } HashInfo = GetHashInfo (HashAlgorithm); if (HashInfo == NULL) { return EFI_UNSUPPORTED; } *HashSize = HashInfo->HashSize; return EFI_SUCCESS; }
int _tmain(int argc, _TCHAR* argv[]) { if(argc == 1) return ErrorReport(L"Please specify a localisation file."); else if(argc == 2) return ErrorReport(L"Please specify the name of the array."); else if(argc == 3) return ErrorReport(L"Please specify the name of the name-array."); else if(argc == 4) return ErrorReport(L"Please specify the counter parameter."); else if(argc == 5) return ErrorReport(L"Please specify one or more categories you are looking for."); tstring file, name, counter_name, id_array_name; file = argv[1]; name = argv[2]; id_array_name = argv[3]; counter_name = argv[4]; int id = 1; for(int i = 5 ; i < argc ; ++i) { std::vector<tstring> information; GetHashInfo(argv[i], information); FillArray(information, name, id_array_name, file, id); } tcout << L"set \"" << counter_name << L"=" << (id - 1) << L"\""; return 0; }
/** Creates a hash for the specified message text. The hash is not extendable. The output is final with any algorithm-required padding added by the function. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. @param[in] Message Points to the start of the message. @param[in] MessageSize The size of Message, in bytes. @param[in,out] Hash On input, points to a caller-allocated buffer of the size returned by GetHashSize() for the specified HashAlgorithm. On output, the buffer holds the resulting hash computed from the message. @retval EFI_SUCCESS Hash returned successfully. @retval EFI_INVALID_PARAMETER This or Hash is NULL. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver or HashAlgorithm is Null. @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available or MessageSize is greater than platform maximum. **/ EFI_STATUS EFIAPI BaseCrypto2Hash ( IN CONST EFI_HASH2_PROTOCOL *This, IN CONST EFI_GUID *HashAlgorithm, IN CONST UINT8 *Message, IN UINTN MessageSize, IN OUT EFI_HASH2_OUTPUT *Hash ) { EFI_HASH_INFO *HashInfo; VOID *HashCtx; UINTN CtxSize; BOOLEAN Ret; EFI_STATUS Status; Status = EFI_SUCCESS; if ((This == NULL) || (Hash == NULL)) { return EFI_INVALID_PARAMETER; } if (HashAlgorithm == NULL) { return EFI_UNSUPPORTED; } HashInfo = GetHashInfo (HashAlgorithm); if (HashInfo == NULL) { return EFI_UNSUPPORTED; } // // Start hash sequence // CtxSize = HashInfo->GetContextSize (); if (CtxSize == 0) { return EFI_UNSUPPORTED; } HashCtx = AllocatePool (CtxSize); if (HashCtx == NULL) { return EFI_OUT_OF_RESOURCES; } Ret = HashInfo->Init (HashCtx); if (!Ret) { Status = EFI_OUT_OF_RESOURCES; goto Done; } Ret = HashInfo->Update (HashCtx, Message, MessageSize); if (!Ret) { Status = EFI_OUT_OF_RESOURCES; goto Done; } Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash); if (!Ret) { Status = EFI_OUT_OF_RESOURCES; goto Done; } Done: FreePool (HashCtx); return Status; }